Can anyone explain this behavior of the increment operation? Why 5 6 7 is not returning | SoloLearn: Learn to code for FREE!

0

Can anyone explain this behavior of the increment operation? Why 5 6 7 is not returning

https://code.sololearn.com/c4H9FfgU68Sx/?ref=app

3/5/2020 9:24:46 AM

Mansa Saxsena

2 Answers

New Answer

+1

According to standard, the order of evaluation of function parameters is undefined. They can be calculated in any order. For example, 4th parameter may be evaluated first, then 3rd, and then 2nd, as in your case. But other compiler can do it in other order.

0

When you run the code, you'll notice that there's a warning, telling you that operation on <some-variable> maybe undefined. Strange behaviour like this is expected, when you try to read a data while at the same point of execution you are also modifying the data. Which event happens in sequence is compiler dependent, it can be read-write or write-read. Output in one compiler may differ to that in another. You should avoid it, bad practice, though it's common in challenges or quizzes I presume. Read about it here: https://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points