ProgrammingHardWipro · Capgemini pattern

int x = 7; int *a = &x, *b = &x; *a ^= *b; *b ^= *a; *a ^= *b; What is x afterwards?

  1. A. 0
  2. B. 14
  3. C. -7
  4. D. undefined

Correct answer: A. 0

The first XOR makes x equal 0, and every later XOR of 0 with 0 leaves it at 0. Both pointers refer to the same int, so these modifications are well defined.

More C Programming questions

Exams that ask this topic