Why is the C statement i = i++ + 1; a problem?
Correct answer C. It modifies i twice without sequencing, which is undefined behaviour
Explanation
The assignment and the side effect of i++ both modify i, and C11 does not sequence the side effect of i++ relative to the assignment's store. Two unsequenced modifications of the same object are undefined behaviour, so different compilers may give different results. GCC warns with -Wsequence-point under -Wall. Write i = i + 1 or i++ alone instead.
Answer checked How we write and check questions
Discussion