Why does a%b produce SIGFPE when b is zero?

The operation triggers SIGFPE:

SIG is a common prefix for signal
names; FPE is an acronym for
floating-point exception. Although
SIGFPE does not necessarily involve
floating-point arithmetic, there is no
way to change its name without
breaking backward compatibility.

GDB is a bit clearer about this and calls it “Arithmetic exception”:

(gdb) run
Starting program: /home/emil/float

Program received signal SIGFPE, Arithmetic exception.
0x0804837d in main () at float.c:4
4           int c=a%b;

Leave a Comment