+ 5

Can anyone explain to me why in the output of this code, a= 23 ????

https://code.sololearn.com/cocn4v0EVXR3/?ref=app

15th Dec 2018, 2:41 PM
🌚a 2fik
🌚a 2fik - avatar
2 ответов
+ 4
Hi there, You have to understand what ++ does with the varaible If you use ++ or -- pre to the variable(like ++x) then it will update the variable first then it will be used in evaluation But if you use them post to the variable (like x++) then it will first use the value then it will update the variable So for your case you used the post version a = 5; b = (a++) + (a++); //eq turns to be 5 + 6 not 6 + 7 but at val of a = 7 at end; So b = 11 Next line a = (b++) + (b++); //Eq is 11 + 12 = 23 At end b = 13 I hope it helps Thank you😊
15th Dec 2018, 3:24 PM
Bad_Bits
Bad_Bits - avatar
+ 4
Anurag Kumar I understood it, thank u for ur help 👍
15th Dec 2018, 5:59 PM
🌚a 2fik
🌚a 2fik - avatar