ProgrammingHard
int x = 16; printf("%d", x >> 2 ^ 3); What is printed?
- A. 4
- B. 7
- C. 1
- D. 12
Correct answer: B. 7
>> has higher precedence than ^, so the expression is (16 >> 2) ^ 3 = 4 ^ 3 = 100 ^ 011 = 111 = 7. 4 forgets the XOR, and 1 treats ^ as subtraction (4 - 3).
More C Programming questions
- unsigned v = 12; printf("%u", v & -v); What is printed?
- printf("%u", (0u - 1u) % 10); What is printed with 32-bit unsigned int?
- printf("%d", 10 % 3 2 ^ 1); What is printed?
- printf("%d", (unsigned char)~0x0F); What is printed?
- printf("%d", 1 << 3 == 8); What is printed?
- printf("%d", 5 & 6 == 4); What is printed?