In C, what is the result of integer division of 5 by 2?

The story behind the answer

In C, integer division of 5 by 2 produces 2.

When both operands of the `/` operator have an integer type, C performs integer division. The mathematical quotient is 2.5, but the fractional part cannot be represented in an integer result, so it is discarded. Since C99, integer division truncates toward zero, making the result 2 for `5 / 2`.

This is different from floating-point division. If either operand is converted to a floating-point type—such as in `5.0 / 2` or `(double)5 / 2`—the result is 2.5. Writing `2.5` as an answer confuses integer arithmetic with floating-point arithmetic.

Negative values are a common source of confusion. For example, `-5 / 2` evaluates to `-2`, not `-3`, because truncation is toward zero. The remainder operator follows the same division relationship: `5 % 2` is 1, and the quotient and remainder satisfy `5 == (5 / 2) * 2 + (5 % 2)`.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: