ProgrammingModerateProduct-company MCQ pattern

What is printed?

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

Correct answer: B. 2

Precedence order is + then << then &: ((2 + 3) << 1) & 7 = (5 << 1) & 7 = 10 & 7 = 1010 & 0111 = 2. Grouping 3 << 1 & 7 first gives 2 + 6 = 8.

More C Programming questions

Exams that ask this topic