ProgrammingHardGATE CS · Campus placements

int x = 12; x = x ^ (x >> 2); What is x?

  1. A. 10
  2. B. 6
  3. C. 12
  4. D. 15

Correct answer: D. 15

x >> 2 is 3 and 12 XOR 3 = 1100 XOR 0011 = 1111 = 15. Shifting by two rather than one moves the bits further, so the result differs from a Gray code step.

More C Programming questions

Exams that ask this topic