ProgrammingModerateTCS NQT · Infosys pattern

What is printed?

What is printed?
printf("%d", 1 << 3 + 1);
  1. A. 16
  2. B. 8
  3. C. 2
  4. D. 9

Correct answer: A. 16

Additive operators bind tighter than shift operators, so this is 1 << (3 + 1) = 1 << 4 = 16. Reading it as (1 << 3) + 1 gives the trap answer 9.

More C Programming questions

Exams that ask this topic