Originally posted by peter greaves:
int k=6;
k = k++;
System.out.println(k);
prints
6
Hi,
k++ returns the current value of k and then increments it.
++k increments k and then returns the incremented value.
When u write
k = k++; things happen in the following sequence:
1 - the current value of k is returned (6).
2 - k is incremented, and its value becomes 7.
3 - the assignment is executed, and the value returned by the expression (6) becomes k's value.
Thus, when u print out the value of k, you get a 6, not a 7!!
Regards,
Jonathas d-_-b