ProgrammingHard
printf("%d", (3 & 1) + (3 | 1) + (3 ^ 1)); What is printed?
- A. 2
- B. 7
- C. Implementation-defined: it depends on the sign representation
- D. 6
Correct answer: D. 6
With 3 = 11 and 1 = 01: 3 & 1 = 1, 3 | 1 = 3 and 3 ^ 1 = 2, total 6. 7 reads ^ as a power (3^1 = 3), 2 swaps in the logical operators (1 + 1 + 0), and the sign representation never matters for non-negative values.
More C Programming questions
- 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?
- int i = 3; int j = i-- - --i; printf("%d %d", i, j); What is printed?