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 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 "increment operator Watch "increment operator New topic
Author

increment operator '++'

s khosa
Ranch Hand

Joined: May 15, 2003
Posts: 72
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

Joined: May 25, 2003
Posts: 111
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

Joined: May 25, 2003
Posts: 111
Sorry about the smilie, total mistake caused by ;) & me not disabling the bloody thing.
La Vish
Ranch Hand

Joined: Apr 17, 2002
Posts: 158
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!


La Vish
SCJP 1.4, President 60s Club
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi sumeer
You can find the related threads click here you will find a interesting nested link too.....


Francis Siu
SCJP, MCDBA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: increment operator '++'
 
Similar Threads
Doubt with Kathy sierra chapter 10
Output of this...........?How you got that?
Mock Exam doubt increment expresion
Incremeant - Marcus Greens Exam-3, Q-54
confusion .....