File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on Post Increment operator.

 
Sathi Krishna
Ranch Hand
Posts: 51
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
j++ first evaluates, then increments. You hence always assign zero to j.
 
Ankit Garg
Sheriff
Posts: 9496
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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??
 
Anuj Prashar
Ranch Hand
Posts: 99
Android Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this link on javaranch.
http://faq.javaranch.com/java/PostIncrementOperatorAndAssignment
 
Sathi Krishna
Ranch Hand
Posts: 51
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank You, Now its clear !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic