Difficulty: Easy
Correct Answer: 9
Explanation:
Introduction / Context:
This question checks your understanding of post-increment in a return expression and a subsequent pre-decrement before printing. The behavior is completely defined in C.
Given Data / Assumptions:
Concept / Approach:
The operator i++ yields the original value and then increments the local copy. Since function parameters are by value, the caller receives 10. The pre-decrement operator --i decrements first, then yields the new value.
Step-by-Step Solution:
Call fun(10): returns 10 (post-increment proceeds on a temporary inside fun).Assign i = 10.Compute --i: now i = 9.Print 9.
Verification / Alternative check:
If you changed the body to return (++i);, then i in main would be 11, and --i would print 10.
Why Other Options Are Wrong:
“10/11/8” do not match the exact operator sequence. Behavior is not undefined here.
Common Pitfalls:
Confusing pre- and post-increment semantics; assuming pass-by-reference incorrectly modifies the caller’s variable in the callee.
Final Answer:
9
Discussion & Comments