# What is the behavior of integer division?

###### Posted By: Anonymous

For example,

```
int result;
result = 125/100;
```

or

```
result = 43/100;
```

Will result always be the floor of the division? What is the defined behavior?

## Solution

Will result always be the floor of the division? What is the defined behavior?

Not quite. It rounds toward 0, rather than flooring.

6.5.5 Multiplicative operators

6When integers are divided, the result of the / operator is the algebraic quotient with any

fractional part discarded.^{88)}If the quotient a/b is representable, the expression

(a/b)*b + a%b shall equal a.

and the corresponding footnote:

- This is often called ‘‘truncation toward zero’’.

Of course two points to note are:

3The usual arithmetic conversions are performed on the operands.

and:

5The result of the / operator is the

quotient from the division of the

first operand by the second; the

result of the % operator is the

remainder.In both operations, if the

value of the second operand is zero,

the behavior is undefined.

[Note: Emphasis mine]

###### Answered By: Anonymous

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.