In following piece of code why is 'i' still 0 after i++? int i=0; i=i++; System.out.println(i); In expression 'i=i++' first value 0 is assigned to i and then i++ is done. Would ++ operator increment value of i by '1', which is '0' after assignment? So i should be 1?
If the line was simply i++; then i would be 1. The trick here is the line in your code (i=i++ actually gives the variable i the value of i before the incrementation, thus the ++ has no effect on the newly assigned variable i.