ProgrammingVery hardTCS NQT · Infosys

What is the bitwise XOR of all integers from 1 to 10, that is 1 ^ 2 ^ 3 ^ ... ^ 10?

  1. A. 11
  2. B. 10
  3. C. 9
  4. D. 1

Correct answer: A. 11

Prefix XOR of 1..n depends on n mod 4: it equals n when n mod 4 is 0, 1 when it is 1, n+1 when it is 2, and 0 when it is 3. Since 10 mod 4 = 2, the result is 11.

More C Programming questions

Exams that ask this topic