Consider:
int m = 2, n;
n = m++ + (++m);
In C output is:
m = 4, n = 4;
In Java output is:
m = 4, n = 5;
How does this happen?
It can differ because C does not allow a correct program to contain such an expression - C does not define the behaviour of such a program. This gives C compilers wide latitude in how they interpret such expressions.
Java more tightly constrains implementations by defining the expected behaviour of expressions like this.
(The rule that this breaks in C is that an expression may not modify the value of an object more than once without an intervening sequence point).
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