ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
int a, b, c;
a = b = c = 5;
printf("%d %d %d", a, b, c);
  1. A. 5 0 0
  2. B. Compilation error
  3. C. 0 0 5
  4. D. 5 5 5

Correct answer: D. 5 5 5

Assignment is right-associative: a = (b = (c = 5)). c is set to 5, that value is assigned to b, and that value is assigned to a, so all three become 5.

More C Programming questions

Exams that ask this topic