This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
The result of the prefix or postfix increment expression is not a variable, but a value. For prefix or postfix increment the value 1 is added to the value of the variable and the sum is stored back into the variable. The value of the prefix increment expression is the value of the variable after the new value is stored. The value of the postfix increment expression is the value of the variable before the new value is stored.
in line 1 ++i evaluates to value 11 value of expression=11 & i=11 i=value of expression in line 2 i++ evaluates to value 11 value of expression=11 & i=12 i=value of expression => i is overwritten with value 11
I have seen hunderds of threads on this particular topic. Mostly, the explanation given is 'reverse-engineered'. Interestingly, if you do the same in C, you'll get 12 as your answer. C != Java, but when you read the definition of the post-increment operator, do you find any difference?
Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.