Example

Failures/fpe.c

#include <stdio.h>
int main() {
int a = 5;
int b = 0;
'b' initialized to 0
int unusedVar = 10;
unused variable 'unusedVar'
unused variable 'unusedVar'
unused variable ‘unusedVar’
double result = a / b;
Division by zero
Division by zero
printf("Result: %d\n", result);
format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’
format specifies type 'int' but the argument has type 'double'
format specifies type 'int' but the argument has type 'double'
if (b != 0) {
double result = (double)a / b;
printf("Safe division: %d\n", result);
format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’
format specifies type 'int' but the argument has type 'double'
format specifies type 'int' but the argument has type 'double'
} else {
printf("Warning: Division by zero!");
}
return 0;
}