+ 5
Can anyone explain to me why in the output of this code, a= 23 ????
2 RĂ©ponses
+ 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đ
+ 4
Anurag Kumar I understood it, thank u for ur help đ