ProgrammingModerateWipro · Capgemini pattern

What is printed?

What is printed?
int a = 5, b, c;
b = a > 3 ? 10 : 20;
c = (b == 10) ? a + b : 0;
printf("%d %d %d", a, b, c);
  1. A. 5 20 0
  2. B. 5 10 0
  3. C. 5 10 10
  4. D. 5 10 15

Correct answer: D. 5 10 15

a > 3 is true, so b = 10; then b == 10 is true, so c = 5 + 10 = 15. The conditional operator evaluates only the selected branch.

More C Programming questions

Exams that ask this topic