ProgrammingHardTCS NQT · Infosys pattern

What is printed?

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

Correct answer: B. 7 5 7

The comma in a declarator list separates full declarations with a sequence point between them: b = a++ reads 5 then increments a to 6; c = ++a increments a to 7 then reads 7. Final state: a=7, b=5, c=7.

More C Programming questions

Exams that ask this topic