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?

Recommended Answers

All 2 Replies

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.

Thanks once again James :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.