I have a very basic doubt, I tried the following code in C.
i=(++i)+(++i)+(++i);
I expected the answer to be 6 but the answer came out to be 7. How is it this possible ?increment in C
I have a very basic doubt, I tried the following code in C.
i=(++i)+(++i)+(++i);
I expected the answer to be 6 but the answer came out to be 7. How is it this possible ?increment in C
Assigning multiple times to a single memory location between two sequence points yields undefined behaviour, no certain value or behaviour is to be expected.
Rule of thumb: Do not assign multiple times to a single value within a single expression:
++i; ++i; i+= i; // okay
++i + ++i; // not okay