ProgrammingHard
int x = 5; x ^= x << 1; printf("%d", x); What is printed?
- A. 10
- B. 5
- C. 15
- 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
- printf("%d", (3 & 1) + (3 | 1) + (3 ^ 1)); What is printed?
- unsigned int x = 0xF0F0F0F0u; printf("%u", x >> 28); What is printed?
- printf("%d", 20 / 6 6 + 20 % 6); What is printed?
- printf("%d", 2 3 % 5); What is printed?
- printf("%d", (1 << 2) + 1); What is printed?
- int a = 7; int b = a++ 2; printf("%d %d", a, b); What is printed?