// This is an example of integer overflow // This is when we try to go beyond the limits of what // a type can store // For ints this is undefined behaviour // On dcc you will get a run-time error // with gcc it may wrap around and you will get incorrect numbers! #include #include int main(void){ int x = INT_MAX; printf("%d + 1 = ", x); x = x + 1; //overflow undefined behaviour printf("%d\n", x); int y = INT_MIN; printf("%d - 1 = ", y); y = y - 1; //overflow undefined behaviour printf("%d\n", y); return 0; }