ProgrammingVery hard

int a = 0; for (int i = 0; i < 1000000; i++) a ^= i; printf("%d", a); What is printed?

  1. A. 1000000
  2. B. 999999
  3. C. 0
  4. D. 1

Correct answer: C. 0

The XOR of 0 through n is 0 when n mod 4 == 3, and 999999 mod 4 is 3, so the result is 0.

More C Programming questions

Exams that ask this topic