....
SCJP2 2001 84%<br />SCJD2 2003 100%
Originally posted by Raj Mehra:
i=i++ can be broken into two simple statements:-
i=i;//i is 0 here
i=i+1;//i becomes 1.
When stored 0 is stored 1st and 1 after that. Now while printing with a stack approach Last in Last Out prints 0 and not 1.
....
....
SCJP2 2001 84%<br />SCJD2 2003 100%
SCJP
Visit my download page
15.14.1 Postfix Increment Operator ++
PostIncrementExpression:
PostfixExpression ++
A postfix expression followed by a ++ operator is a postfix increment expression. The result of the postfix expression must be a variable of a numeric type, or a compile-time error occurs. The type of the postfix increment expression is the type of the variable. The result of the postfix increment expression is not a variable, but a value.
At run time, if evaluation of the operand expression completes abruptly, then the postfix increment expression completes abruptly for the same reason and no incrementation occurs. Otherwise, the value 1 is added to the value of the variable and the sum is stored back into the variable. .... The value of the postfix increment expression is the value of the variable before the new value is stored.
....
Originally posted by Raj Mehra:
i=i++ can be broken into two simple statements:-
i=i;//i is 0 here
i=i+1;//i becomes 1.
When stored 0 is stored 1st and 1 after that. Now while printing with a stack approach Last in Last Out prints 0 and not 1.
Don't get me started about those stupid light bulbs. |