Can anyone explain -in simple words as possible- what happens in the first code so that it prints the result that way?
Undefined behavior.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,408
Skill Endorsements: 55
What i asked is, how to write the the code, which don't give a undefined behavior still giving the correct output for this exact question.
The undefined behavior comes from modifying the same variable more than once in the same expression. To get rid of undefined behavior, first figure out what output you want, then break up the expression to do it. In the first post on this thread, the first code snippet has undefined behavior and the second code snippet is the right way to fix it.
deceptikon
Challenge Accepted
3,502 posts since Jan 2012
Reputation Points: 822
Solved Threads: 481
Skill Endorsements: 58
Question Answered as of 1 Year Ago by
Moschops,
PrimePackster,
Narue
and 1 other