ProgrammingModerate

printf("%d", (1 << 2) + 1); What is printed?

  1. A. 8
  2. B. 3
  3. C. 4
  4. D. 5

Correct answer: D. 5

The parentheses group the shift, so 1 << 2 = 4 and adding 1 gives 5. Without them + binds tighter than <<, and 1 << 2 + 1 would be 1 << 3 = 8, the tempting wrong option.

More C Programming questions

Exams that ask this topic