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.
public class test{ public static void main(String args[]) { int i=0; i = i++; System.out.println(i); } } Answer is : 0. Can any one tell me what happens to increment operator?
Anand<br />SCJP 1.4, SCWCD 1.4, SCEA 5.0(1/3)
Mohan Bhakri
Greenhorn
Joined: Nov 20, 2003
Posts: 1
posted
0
Hi Anand
In your program , the expression i = i++ ; is undefined .
Vicken Karaoghlanian
Ranch Hand
Joined: Jul 21, 2003
Posts: 522
posted
0
Hi Anand, This topic was discussed many times here. You can do a search. I am sure you'll get interesting results. Simply put:
According to the JLS the postfix operator always returns its old value then increment it.
Hope this helps. [ December 04, 2003: Message edited by: Vicken Karaoghlanian ]
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Jay Rosenthal
Greenhorn
Joined: Dec 04, 2003
Posts: 2
posted
0
In the line "i = i++;", the i on the right side of = is not incremented until afterthe value of i is assigned to the i on the left side of =. So, i is still 0 and that's what prints.