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
before increment assignment is there....
Posted by ruchi and hema on November 12, 2000 at 4:40 AM
it is very simple to understand this concept.....
in case of postincrement(a++),always assignment is first(i.e value of
'a' will assigned first and later will be incremented.
Note : But this increment is reflected only during the arithmetic
operations. i.e in this code if along with a=a++ if it is
written as a=a++ +2 then the value will be changed to 3..
i.e. first 'a' will be 1 and later after assignment
value of 'a' will be changed to 2..so here o/p will be 3..
Just remember that during post increment if arithmetic
operators are not there then the value will be same..but
during preincrement this is not the case...
Hema and Ruchi
> I am not able to understand why all the printed answers for a is 1 while it is supposed to increase
> class test3
> public static void main(String s)
> int a = 1;