---
name: "div"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/div"
---

# div(3)

compute quotient and remainder of an integer division

## NAME

div, ldiv, lldiv, imaxdiv - compute quotient and remainder of an integer division

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <stdlib.h>
```

**div\_t div(int** *numerator***, int** *denominator***);** **ldiv\_t ldiv(long** *numerator***, long** *denominator***);** **lldiv\_t lldiv(long long** *numerator***, long long** *denominator***);**

**#include \<inttypes.h\>**

**imaxdiv\_t imaxdiv(intmax\_t** *numerator***, intmax\_t** *denominator***);**

Feature Test Macro Requirements for glibc (see [**feature\_test\_macros**(7)](/feature_test_macros/7.md)):

**lldiv**():

```
    _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
```

## DESCRIPTION

The **div**() function computes the value *numerator/denominator* and returns the quotient and remainder in a structure named *div\_t* that contains two integer members (in unspecified order) named *quot* and *rem*. The quotient is rounded toward zero. The result satisfies *quot\*denominator+rem = numerator*.

The **ldiv**(), **lldiv**(), and **imaxdiv**() functions do the same, dividing numbers of the indicated type and returning the result in a structure of the indicated name, in all cases with fields *quot* and *rem* of the same type as the function arguments.

## RETURN VALUE

The *div\_t* (etc.) structure.

## ATTRIBUTES

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **div**(), **ldiv**(), **lldiv**(), **imaxdiv**() | Thread safety | MT-Safe |

## STANDARDS

C11, POSIX.1-2008.

## HISTORY

POSIX.1-2001, C89, C99, SVr4, 4.3BSD.

**lldiv**() and **imaxdiv**() were added in C99.

## EXAMPLES

After

```
div_t q = div(-5, 3);
```

the values *q.quot* and *q.rem* are -1 and -2, respectively.

## SEE ALSO

[**abs**(3)](/abs/3.md), [**remainder**(3)](/remainder/3.md)
