← printf, scanf & Overflow

Unsigned Wraparound

medium

Read one unsigned int and print the value one greater than it, in the form Next: 42. Your program should handle n = 4294967295 (which is UINT_MAX, i.e. 2^32 - 1) correctly – that’s the whole point of the exercise.

Unlike signed overflow, this has a single, boring, guaranteed answer: unsigned integer arithmetic in C wraps modulo 2^32 (for a 32-bit unsigned int) by definition, not as an implementation quirk. UINT_MAX + 1 == 0 is something you can rely on in real code – it’s the reason, for example, that an unsigned loop counter counting down past zero doesn’t go negative, it wraps to a huge positive number, which is a real bug pattern worth recognizing.

Your solution

"Run" uses the sample stdin ("41"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution