Can some one explain me how post increment works in Java ?
public static void main(String[] args) {
int a = 10;
/*
* 1. "a" is assigned to "b"
* 2. Then a gets incremented by 1
*/
int b = a++;
System.out.println(b); //prints 10
System.out.println(a); //prints 11
int x = 10;
/*
* 1. "x" is assigned to "x"
* 2. Then "x" is not getting incremented by 1
*/
x = x++;
System.out.println(x); //prints 10
}
So when we have same variable on both sides result is different. Please explain...