This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi all Please explain this: final public static void main(String args[]) { int i = 0; i = i++; i = i++; i = i++; System.out.println(i); // prints 0, since = operator has the lowest precedence. Minakshi
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
The order in which things happen in statement execution is what causes this result. 1) - the left side asignment address to i is calculated 2) - the current value of i is grabbed 3) - the current value of i is incremented finally, the value of i from step 2 is stored in the address calculated in step 1, replacing the value from step 3 Bill
Hi, Here the catch is that when u do something like i = i++ the incrementation will never take place. ie, in your case i is always equal to zero. Also try a search for this topic in this forum, u will find a lot of discussions.
Latha Kalaga
Ranch Hand
Joined: Nov 13, 2000
Posts: 96
posted
0
Are you saying here that in i = i++; after assigning 0 to i, the incremented value is not stored back in i??? I guess I am confused by - the left side assignment address to i is calculated. Please could you explain?? Thanks.
Originally posted by William Brogden: The order in which things happen in statement execution is what causes this result. 1) - the left side asignment address to i is calculated 2) - the current value of i is grabbed 3) - the current value of i is incremented finally, the value of i from step 2 is stored in the address calculated in step 1, replacing the value from step 3 Bill