This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

increment operator '++'

 
s khosa
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In following piece of code why is 'i' still 0 after i++?
int i=0;
i=i++;
System.out.println(i);
In expression 'i=i++' first value 0 is assigned to i and then i++ is done. Would ++ operator increment value of i by '1', which is '0' after assignment? So i should be 1?
 
Dave Johnson
Ranch Hand
Posts: 111
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the line was simply i++; then i would be 1.
The trick here is the line in your code (i=i++ actually gives the variable i the value of i before the incrementation, thus the ++ has no effect on the newly assigned variable i.
 
Dave Johnson
Ranch Hand
Posts: 111
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about the smilie, total mistake caused by ;) & me not disabling the bloody thing.
 
La Vish
Ranch Hand
Posts: 161
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,
You can actually use the edit button to disable the smiley face so that you don't have to feel sorry for that!
 
Francis Siu
Ranch Hand
Posts: 867
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi sumeer
You can find the related threads click here you will find a interesting nested link too.....
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic