ProgrammingHard
What value does a[i] ^= a[j] leave when i and j refer to the same element?
- A. The original value, because XOR with itself is the identity
- B. 0, because x ^ x = 0 for every x
- C. The value doubled
- 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
- Which expression sets bit 31 of an unsigned 32-bit variable x with no undefined behaviour?
- The sequence n ^ (n >> 1) for n = 0, 1, 2, 3 gives what list?
- For positive values below 2^31, which product is guaranteed to fit in a signed 64-bit integer?
- What is the multiplicative inverse of 2 modulo 7?
- In C, what is the result of 7 / -2 and 7 % -2?
- An unsigned short variable holds 65535 and is then incremented once with x++. What value does it hold?