0

Pre and post(javascript vs cpp)

I ran this piece of code on JavaScript var a = 0; alert(++a + (++a*a++)); and I got 5 as output. after that I ran this same code on c++ but that time I got 9 as output. now how the hell that happen can someone explain me please.

28th Dec 2017, 9:27 PM
ARNAB BISWAS
ARNAB BISWAS - avatar
1 Odpowiedź
+ 15
It depends on what order the compiler evaluates the function arguments in. This procedure is different not only for different languages, but even for different compilators of the same language. And this is called "side-effects". More about it: http://www.learncpp.com/cpp-tutorial/33-incrementdecrement-operators-and-side-effects/
28th Dec 2017, 10:15 PM
NezhnyjVampir