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
Artima Forums.
Message:
before increment assignment is there....
Posted by ruchi and hema on November 12, 2000 at 4:40 AM
hello... 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... ThanX 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; > System.out.println(a); > a=a++; > System.out.println(a); > > a=a++; > a=a++; > System.out.println(a); > > a=++a; > System.out.println(a); > a=++a; > a=++a; > System.out.println(a); > } > }
Replies:
|