C programming stdlib.h function - ldiv_t ldiv(long int numer, long int denom)

The ldiv() function is declared in the stdlib.h header file in C programming language. It takes two long integer arguments, numer and denom, and returns a ldiv_t structure containing the quotient and remainder of the division as long integers.

The prototype of the ldiv() function is as follows:

‮t refer‬o:theitroad.com
ldiv_t ldiv(long int numer, long int denom);

The ldiv() function is used to perform a long integer division and obtain both the quotient and the remainder. The result is returned as a ldiv_t structure, which contains two members:

  • quot: the quotient of the division (numer/denom).
  • rem: the remainder of the division (numer%denom).

For example, if you call ldiv(10, 3), the function would return a ldiv_t structure with a quot member of 3 (the integer part of 10/3) and a rem member of 1 (the remainder of 10/3).

The ldiv() function can be useful in situations where you need to perform a long integer division and obtain both the quotient and the remainder.