🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Bitwise Operators in C: all 15 questions

Quiz: Bitwise Operators in C · Question 12 of 15

What does this print? (code)

What does this print?

#include <stdio.h>
int main(void) {
    int a = 5, b = 9;
    a = a ^ b;
    b = a ^ b;
    a = a ^ b;
    printf("%d %d\n", a, b);
    return 0;
}
  1. A.5 9
  2. B.9 5
  3. C.12 5
  4. D.0 0
Answer & explanation

Correct answer: 9 5

Three XORs swap the two values without a temporary variable, because x ^ x is 0 and x ^ 0 is x.

Can you get the rest right without peeking?

Take the timed Quiz: Bitwise Operators in C quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →