Possible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)
increment values in printf
I have a two double arrays x
and y
and integer i
. My question is whether the statement:
double res = x[i] * y[i++];
is always equal to the statement:
double res = x[i] * y[i];
i++;
Is it possible that some compilers would change x[i] * y[i++]
into y[i++] * x[i]
, which obviously produces different result?
No -- x[i] + y[i++]
has undefined behavior. You're modifying the value of i
and also using the value i
without an intervening sequence point, which gives undefined behavior1.
No, it is undefined when the increment occurs.
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