writes:
> int i=10;
> i = i++;
....
> why it is printing 10 instead of 11 ??
Because that's what you ask it to do (I assume SOP is a shorthand
for System.out.print).
Execution of the assignment expression "i = i++" first evaluates the
right hand side (i++) and then assigns the value to the variable "i".
Evaluation of i++ is defined to
1) take the value of the variable "i".
2) increment the variable "i"
3) return the value from 1), i.e., the *original* value.
So, you assigment does the following:
- take the value of i (10)
- increment i (i is now 11)
- take the original value (10) and assign it to i (i is now 10)
Then you write i, which is, as expected, 10.
You probably want to change "i = i++" into either "i = i + 1" or "i++",
either will do what you expect (increment the value of "i" by 1).
/L
--
Lasse Reichstein Nielsen -
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'