ProgrammingVery hardGATE CS · Campus placements

int x = 0; for (int i = 0; i < 5; i++) x = x ^ i << 1; What is x at the end?

  1. A. 8
  2. B. 2
  3. C. 6
  4. D. 0

Correct answer: A. 8

<< binds tighter than ^, so each step XORs x with i shifted left by one: the values run 0, 2, 6, 0, 8. The final value is 8.

More C Programming questions

Exams that ask this topic