ProgrammingHard

What value does a[i] ^= a[j] leave when i and j refer to the same element?

  1. A. The original value, because XOR with itself is the identity
  2. B. 0, because x ^ x = 0 for every x
  3. C. The value doubled
  4. D. Undefined behaviour in every case

Correct answer: B. 0, because x ^ x = 0 for every x

XOR-swapping an element with itself clears it, which is why the XOR swap needs distinct addresses.

More C Programming questions

Exams that ask this topic