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?
- A.
Prints 7
- B.
Prints 8
- C.
Prints 9
- 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.