ProgrammingVery hardProduct company OA

What is printed?

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

Correct answer: C. 3 0 3

These are assignments, not comparisons. (a = 2) is true, (b = 0) is false, so the && is false and || must evaluate (c = 3), which is true. The if body then makes a 3. '3 0 0' short-circuits the || wrongly.

More C Programming questions

Exams that ask this topic