# C Programming/stdlib.h/div

From Wikibooks, open books for an open world

< C Programming | stdlib.h(Redirected from C Programming/C Reference/stdlib.h/div)

**div** is a function in C programming language that takes two integers as parameters and returns the result of a division between them. It is specified in ANSI-C, and is included from the stdlib.h header when used. ^{[1]}

div always rounds towards 0, unlike ordinary integer division in C, where rounding for negative numbers is implementation-dependent.

`div`

has a prototype as follows:

`div_t div (int numerator, int denominator)`

The return value, `div_t`

is a special datatype which is specifically used in storing the results of this function. It is defined as follows:

```
typedef struct {
int quot;
int rem;
} div_t;
```

Where `quot`

stores the quotient and `rem`

stores the remainder.

**ldiv** and **lldiv** are similar functions that divide integers of type `long`

and `long long`

, respectively; and return a structure of type `ldiv_t`

and `lldiv_t`

, respectively.

```
ldiv_t ldiv (long numerator, long denominator );
lldiv_t lldiv (long long numerator, long long denominator);
```

## See also[edit]

- stdlib.h
- stdio.h

## References[edit]

- ↑ http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf chapter 7.20.6.2