div


Perform division of int type to obtain the quotient and remainder

[Classification]

Standard library

[Syntax]

#include <stdlib.h>

div_t __far div(int n, int d);

[Return value]

The structure storing the result of the division is returned. When divided by 0, -1 is set to quotient quot and n is set to remainder rem.

[Description]

This function is used to divide a value of int type

This function calculates the quotient (quot) and remainder (rem) resulting from dividing numerator n by denominator d, and stores these two integers as the members of the following structure div_t.

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

 

When the value cannot be divided, the quotient of the result becomes an integer that is closest to the algebraical quotient but has a smaller absolute value.