if x = 3
and z is unassigned,
why does 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:
The -- prefix
means the decrement will be done before evaluating the expression and the postfix --
means the decrement will be done after evaluation the expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With