0

Why final value of I is 0 in following code Int I=0;I=I++; ?

java post increment

28th Jul 2017, 11:42 AM
vineel kumar
vineel kumar - avatar
3 Answers
+ 12
I = 0 I = I++ Step 1 : I++ returns 0, I becomes 1 Step 2 : Return value (0) is assigned to I => I = 0
28th Jul 2017, 11:56 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 1
l++ is called as post increment. here the value of l is used first and then incremented. eg int l=0; System.out.print(l++); output is 0 ++l is called pre increment. here the value of l is incremented and then used. eg int l=0; System.out.print(++l); output will be 1
28th Jul 2017, 11:59 AM
Devbrath
Devbrath - avatar
+ 1
because if you do l++,program does the operations first then increases value of l.but if you do ++l, program firstly increases value of l then does the operations next. for example : 1 2 int x = 0; int x = 0; x = x++; x = ++x; System.out.println(x); System.out.println(x); run this code and you will understand what i meant.
28th Jul 2017, 12:04 PM
Yusuf Saylam
Yusuf Saylam - avatar