Pre and post(javascript vs cpp) | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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 ответ
+ 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