When i run the following example i get the output 0,2,1
class ZiggyTest2{
static int f1(int i) {
System.out.print(i + \",\");
Pre increment means: add one to variable and return incremented value; Post increment - first return i, then increment it;
int i, j, k;
i = 0; // 0
j = i++; // return i , then increment i
// j = 0; i = 1;
k = ++i; // first increment and return i
//k = 2; i = 2;
// now
++j == --k == --i // would be true => 1==1==1;
// but , using post increment would
// j++ == k-- == i-- // false because => 0 == 2 == 2;
// but after that statement j will be 1, k = 1, i = 1;