The o/p is 10. But shouldn't it be 9? Is it got anything to do with Postfix or variable scoping has a role to play?

Edited by JamesCherrill: Code snippets are for sharing working code. Your question fits the "Discussion" type better.

5 Years
Discussion Span
Last Post by rahul.ch

That's just how postfix works. O
n line 4 the value of x-- (10) is passed to the met method, then the value of x is decremented. In the method met, the value of the expression x-- (also 10) is evaluated. The parameter x is them decremented, but this is irrelevant because it immedtately goes out of scope. The evaluated value (10) is then returned. Finally back on line 4 that value is assigned to x.

ps rahul - if you are satisfied with an answer / answers to ypur questons please mark the thread "solved" so others fgind it useful as well.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.