ProgrammingHardTCS NQT · Infosys pattern

What is printed?

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

Correct answer: A. 2 0 0 1

&& stops when the left side is false (1 > 5 is false), so the first ++b never runs. || stops when the left side is true (2 > 0), so the second ++b never runs either. b stays 0.

More C Programming questions

Exams that ask this topic