+ 2

Why this thing happens?Explain it guys.

Guess the output and then run this snippet and plz explain why this thing is happning? https://code.sololearn.com/cYbWV0ZoDSGC/?ref=app

26th Dec 2017, 2:07 AM
shiwank agrahari
shiwank agrahari - avatar
4 Respuestas
+ 10
in post increment value is first store then increment so here i=87; i=i++; so the value due to post increment first uses the value of i then increment so i=87 if you do i=++i then value first increment then use and i=88 https://www.sololearn.com/Discuss/407846/?ref=app
26th Dec 2017, 2:13 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 2
But According to Logic first i is assigned by 87 then it must be incremented by post increment operator...But this does not happen.. What I think is,it is due to the CPU registers where the statement executes... it stores the value of i in a register and puts in again to the memory address of i hence the assignment value does not change..because increment to i has been overwritten by assigning previous value.
26th Dec 2017, 7:47 AM
shiwank agrahari
shiwank agrahari - avatar