posted 19 years ago
sonal,
int i=5;
i=i++;
System.out.println(i);
the value of i will be 5 only.
In the line i=i++; means i=5 then increment by 1;
so i will again assigned a value of 5,
but i will be incremented by 1 after the assignment but it will not be stored anywhere and it will be lost.
But if u say
int i=5;
i++;
System.out.println(i);
now i will print 6.
Here in the line i++; the var i will be incremented and will be stored in i.
And if u change
i=i++; to i=++i;
i=++5;
Here the value is incremented before(preincrement) and then is assigned to i, so this prints 6.
Hope this helps you.