Evaluating expressions in C ++ using unary operators

Why C / C ++ does not evaluate the expression in order from left to right in these cases: Initially x = 1

Evaluating x + ++x gives 4.

If a regular assessment is performed (priority ++ above +), then the result should be 1 + 2 = 3

Similarly:

x + ++x + x gives 6
x + x + ++x gives 4

Why are the results different?

Additional cases:

  x + x++ +x gives 5

Which rule follows instead of C / C ++?

-1
source share

Source: https://habr.com/ru/post/1671360/


All Articles