File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt on Post Increment operator. 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 "Doubt on Post Increment operator." Watch "Doubt on Post Increment operator." New topic
Author

Doubt on Post Increment operator.

Sathi Krishna
Ranch Hand

Joined: Oct 21, 2007
Posts: 51



Why it gives output as 0 , but I thought it was 3.
I am unable to get the above post increment and assignment operation logic sequence.

Can any one clear up.

Thank You
Svk
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
j++ first evaluates, then increments. You hence always assign zero to j.


JDBCSupport - An easy to use, light-weight JDBC framework -
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17



The sequence here for evaluation will be
1. the value of j will be used in the expression (i.e. the statement would be like j = 0, but the assignment will happen later)
2. j will be incremented by 1
3. the assignment of first step will occur thus j will be set to 0

Does this make it clear??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Anuj Prashar
Ranch Hand

Joined: Apr 15, 2008
Posts: 99

Check this link on javaranch.
http://faq.javaranch.com/java/PostIncrementOperatorAndAssignment


SCJP 5,SCWCD 5, RHCT
Sathi Krishna
Ranch Hand

Joined: Oct 21, 2007
Posts: 51


Thank You, Now its clear !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt on Post Increment operator.