DEV Community

Discussion on: The difference between x++ and ++x

Collapse
 
codevault profile image
Sergiu Mureşan

Operators on the same line have equal precedence. When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first. All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.

In Java they are also evaluated from left to right (unless you have a x += 1 instead of x++) then it gets confusing.

This answer goes more in-depth about undefined behaviour in C/C++

Thread Thread
 
ivanovicdanijel profile image
danijel

Thanks a lot!;)