ProgrammingHard

int x = 5; x ^= x << 1; printf("%d", x); What is printed?

  1. A. 10
  2. B. 5
  3. C. 15
  4. D. 0

Correct answer: C. 15

x << 1 uses the old x = 5, giving 10 (1010), and then 5 ^ 10 = 0101 ^ 1010 = 1111 = 15. 0 assumes x ^ x, and 10 forgets the XOR with the old value.

More C Programming questions

Exams that ask this topic