aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes SCJP1.4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "SCJP1.4" Watch "SCJP1.4" New topic
Author

SCJP1.4

Anand Ko
Ranch Hand

Joined: Dec 03, 2003
Posts: 79
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
Hi Anand

In your program , the expression i = i++ ; is undefined .
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
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. - What truth? - That there is no spoon!!!
Jay Rosenthal
Greenhorn

Joined: Dec 04, 2003
Posts: 2
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SCJP1.4