int x = INT_MAX; x = x + 1; what does the C standard specify?
Correct answer
D. Signed overflow is undefined behaviour, so the compiler may assume it never happens and optimise accordingly
15 views
D. Signed overflow is undefined behaviour, so the compiler may assume it never happens and optimise accordingly
15 views
Signed overflow is undefined behaviour under the C standard, which is why optimisations may delete checks that presume wrapping. Unsigned arithmetic is defined to wrap modulo 2 to the power N, and that difference is a frequent exam distinction. Code needing wrap-around on signed values should compute in an unsigned type and convert back.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is D? Ask here and get an explanation.