ProgrammingModerate
printf("%d", (1 << 4) | (1 << 2)); What is printed?
- A. 20
- B. 16
- C. 4
- D. 24
Correct answer: A. 20
1 << 4 is 16 (10000) and 1 << 2 is 4 (00100); OR combines the non-overlapping bits into 10100 = 20. 16 drops the second term, and 24 uses 1 << 3 by mistake.
More C Programming questions
- printf("%d", 0x80 >> 7); What is printed?
- int x = 5; x ^= x << 1; printf("%d", x); What is printed?
- 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?