/* * unsigned int addition overflow test * exit(EXIT_FAILURE) if result overflows * print the correct value if everything is good. */ #include #include unsigned int add(unsigned int x, unsigned int y) { unsigned int result = x + y; if (result < x && result < y) { printf("addition overflow\n"); printf("%u\n", result); exit(EXIT_FAILURE); } return result; } int main() { // overflow case unsigned int x = 4294967295u; unsigned int y = 1u; printf("%u\n", add(x, y)); return 0; }