errors/error-3-int.c - Godt alternativ: Forhindring af fejl. | Lektion 7 - slide 10 : 25 Program 4 |
#include <stdio.h> #include <stdlib.h> #include <limits.h> int main(void) { int x = 0, input = 0; /* Prevent division by zero */ if (input != 0) x = 1 / input; /* errno is not changed by the division operator */ else{ printf("Division by zero avoided\n"); x = INT_MAX; } printf("Result is %d\n", x); return 0; }