Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with increment operator.

 
viki Bhardwaj
Ranch Hand
Posts: 74
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Guys,

here i have a question regarding increment operator , code is bellow


in the above code i'm trying to increment the value of x , at the first sop(x) is good ,but at x=x++ here is also ok because here is the post increment so it first assign the value and then increment ..here my
doubt is that...
when i print through sop(x) then it again print 11 as output but what happened with corresponding post incremented value of x which should be 12 logically..but sopln() is unable to get it why???
so please i would like to know about this ....how ??

hopefully, waiting for your reply.

regards:
vivek
 
Winston Gutkowski
Bartender
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek Bhardwaj wrote:when i print through sop(x) then it again print 11 as output but what happened with corresponding post incremented value of x which should be 12 logically..but sopln() is unable to get it why???

It got lost. You need to go back to:
x = x++;
What do you think that does?

Winston
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We also have an article on this : PostIncrementOperatorAndAssignment
 
viki Bhardwaj
Ranch Hand
Posts: 74
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:We also have an article on this : PostIncrementOperatorAndAssignment



Thanks! Seetharaman for sharing the valuable link ,...it was good enough explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic