This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Posted by swapnil on November 27, 2000 at 7:23 AM
i shall try to expalin the difference to u.
In the above program , the first line is assigning zero to x.
In the second line, there are two operators viz assignment operator and the increment operator.When we write x=x++ then the assignment operator gets the preference and the value of R.H.S. x(i.e. zero) is assigned to the L.H.S.(left hand side) x. The increment operator then is operational .so the increment operation is executed. But the incremented value is NOT assigned to any variable.So the incremented value is lost.
now if we print the value of x , it prints the original value i.e. zero.
In this case the initial value of the x variable is zero.
In the second line we see there are two operations viz assignment and the increment.Here also the assignment operator gets the preference.But the value that is assigned to L.H.S x is the value after the increment of the R.H.S. x because the increment operator is preceding the R.H.S. x . This incremented value is being assigned to L.H.S. x . So now the value of x is 1 i.e. one.
hope this helps.