I love MySQL<BR>Sun Certified Programmer for Java 2 Platform
I love MySQL<BR>Sun Certified Programmer for Java 2 Platform
Always Belive On Logic!!
Always Belive On Logic!!
Originally posted by Hassan Naqvi:
[B]
rules of Java for Increment/Decrement operator.
We have two cases in Increment/Decrement operator.
1:Postfix
2:Prefix
Note:The first rule is common for both cases.
Rules
1: The value substituted by Java/Compiler is always assinged.
2: In postfix case, Java/Compiler first substitute the value & then increment/decrement.
3:In prefix case, Java/Compiler first increment/decrement the value & then substitute.
By applying the above rules let us solve the special case
i=i++;
Consider the following segment of code,
i=0; //Line 1
i=i++; //Line 2
S.O.P(i); //Line 3
This is postfix case,therefore applying the second rule.
Firts substitute the value i.e i is substituted by 0 at Line 2.
Then it is incremented(Remeber this increment is made in memory).
Now applying first rule(which is common for both cases).
i.e the value substituted is always assinged.Therefore the value substituted is 0 at Line 2 will be finally assinged to i.
And hence the value printed in Line 3 will be 0.
Hope this help.
Regards,
Hassan.
[/B]
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|