# c Programming/C Reference/stdlib.h/div

From Wikibooks, open books for an open world

< C Programming | C Reference | stdlib.h

This page was imported and needs to be .de-wikifiedBooks should use wikilinks rather sparsely, and only to reference technical or esoteric terms that are critical to understanding the content. Most if not all wikilinks should simply be removed. Please remove {{dewikify}} after the page is dewikified. |

A Wikibookian suggests that this book or chapter be merged into C mathematical operations.Please discuss whether or not this merge should happen on the discussion page. |

**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]

## References[edit]

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