The program fragment: int a = 5, b = 2; printf("%d", a++ + ++b); What does it…

2018

The program fragment: int a = 5, b = 2; printf("%d", a++ + ++b); What does it print?

  1. A.

    Prints 7

  2. B.

    Prints 8

  3. C.

    Prints 9

  4. D.

    None of the above

Attempted by 895 students.

Show answer & explanation

Correct answer: B

a+++ + ++b → interpreted as a++ + ++b

  • a++ → uses 5, then a = 6

  • ++b → becomes 3

Result: 5 + 3 = 8

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Up Lt Grade Assistant Teacher 2025