ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
int a = 1, b = 2, c = 3;
int result = a == 1 && b == 2 || c == 100;
printf("%d", result);
  1. A. 0
  2. B. Compilation error: mixed && and || require parentheses
  3. C. 3
  4. D. 1

Correct answer: D. 1

&& binds tighter than ||, so this parses as `(a==1 && b==2) || (c==100)` = (1 && 1) || 0 = 1 || 0 = 1 (true).

More C Programming questions

Exams that ask this topic