ProgrammingHardIBM · Deloitte pattern

What is printed?

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

Correct answer: A. 10 10

The ternary condition (a > 3), i.e. (5 > 3), is true, so ONLY the true branch, (a = 10), executes; the false branch, (a = 20), never runs at all. a is assigned 10, and that assignment expression's value, also 10, becomes b.

More C Programming questions

Exams that ask this topic