This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Remember Postincrement operator increments the value only after the execution of the current statement (in this case - y = x++ + ++x; )
Before the statement, x is -1 and y is 0.
So as per the explanation above the code must translate to:
y should not get the value from x++ (thats what I thought) but it does.
In fact it behaves as if the code was
That is the only way y can end up with 1 else it should be -1.
May be I am missing some concept here/I might be confused but that is how it works.
I am guessing this has something to do with priority while evaluating an expression. I think ++ has higher priority than +.
Any references will be helpful.
Thanks in advance for any help.
Joined: Jul 29, 2009
Whenever you say
This will make x=1 & y=0
will make x=1 & y=1
In the scenario mentioned above, Pre Increment will be evaluated first, and post increment evaluated last based on precedence so the expression becomes