This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line! See this thread for details.
int i = 0; i = i++; System.out.println(i); The above code in a main statement of a class give output as 0 not 1 why? in i = i++, the assignment operator is done first (l to r), so i is asssigned to i and the '++' is effectively ignored, as it is a post operation increment. Compare this to just i++ on line (2), which gives your expected 1 result
a simple breakdown will surely help u: y=x++ ------- can be broken down to : y=x x=x+1 ============== y=++x ----- can be broken down to : x=x+1 y=x(nothing but x+1) this is the best explanation I found after many years of confusion
A good mnemonic for this: j=i /* . . . . . . . */ ++ ; (compiles and run) Try this 4 sec training. For a permanent result. Rythm it up (high or internal voice) 2 times as this: i=i // say fast ... // wait.. ++ // spit it now! Now whenever you meet j=i++ in Mocks, the Test Center, or the real world, speak it: j=i ... ++ JRoch
[This message has been edited by JRoch (edited April 07, 2000).] [This message has been edited by JRoch (edited April 07, 2000).]