ProgrammingHardTCS NQT · Product company OA

What is printed?

What is printed?
int a = 1;
printf("%d %d", a << 2 + 1, (a << 2) + 1 > 4 == 1);
  1. A. 8 1
  2. B. 5 1
  3. C. 8 0
  4. D. 5 0

Correct answer: A. 8 1

+ binds tighter than <<, so a << 2 + 1 is 1 << 3 = 8, not (1 << 2) + 1 = 5. In the second expression the parentheses give 5; > binds tighter than ==, so (5 > 4) == 1 is 1 == 1, which is 1.

More C Programming questions

Exams that ask this topic