ProgrammingHard
printf("%d", (5 & 3) << 2 | 1); What is printed?
- A. 5
- B. 4
- C. 7
- D. 1
Correct answer: A. 5
The shift binds tighter than &, and | is lowest. So (5 & 3) << 2 = 4, and 4 | 1 = 5.
More C Programming questions
- int x = 16; printf("%d", x >> 2 ^ 3); What is printed?
- 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?