# Division by zero

suggest changeint x = 0; int y = 5 / x; /* integer division */

or

double x = 0.0; double y = 5.0 / x; /* floating point division */

or

int x = 0; int y = 5 % x; /* modulo operation */

For the second line in each example, where the value of the second operand (x) is zero, the behaviour is undefined.

Note that most implementations of floating point math will follow a standard (e.g. IEEE 754), in which case operations like divide-by-zero will have consistent results (e.g., `INFINITY`

) even though the C standard says the operation is undefined.

Found a mistake? Have a question or improvement idea?
Let me know.

Table Of Contents