this question is related to my previous problem. The answer I got was \"It is an Undefined behavior.\"
Please anyone explain:
It's undefined in C, but well-defined in C#:
From C# (ECMA-334) specification "Operator precedence and associativity" section (§14.2.1):
- Except for the assignment operators and the null coalescing operator, all binary operators are left- associative, meaning that operations are performed from left to right. [Example: x + y + z is evaluated as (x + y) + z. end example]
So --i is evaluated first, changing i to 4 and evaluating to 4. Then i++ is evaluating, changing i to 5, but evaluating to 4.