x = 3 and z is unassigned,
z = x-- - --x evaluates to 2?
my professor is lecturing about this at the moment, and I'm currently stuck with this dilemma. Unfortunately, no one can explain why it happens.
on x--, x = 3, and after that it's 2. on --x, x = 1, because substraction (from 2) is done beforehand.
Therefore, 3 - 1 = 2.
Here is the order of operations, illustrated for better understanding:
Ok, its pretty simple:
let's add brackets:
^^ this is how compiler sees your code after tokenizing.
Compiler evaluates equation (right part) from left to right
Current value of X is 3, decremented is 2 - so, in equation we'll get 3, but X will contain new value 2.
Current value of X is 2 (because previous operation decremented it), and now we want to decrease it once again. 2-1 = 1, got it.
Now, back to whole equation: