ProgrammingHard

printf("%d", (3 & 1) + (3 | 1) + (3 ^ 1)); What is printed?

  1. A. 2
  2. B. 7
  3. C. Implementation-defined: it depends on the sign representation
  4. 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

Exams that ask this topic