C Standard Library

C <inttypes.h> - imaxdiv_t structure type



The C <inttypes.h> imaxdiv_t is a structure to represent both the quotient and the remainder of the division of the integral numerator by integral denominator. This is the type returned by imaxdiv() function.

In the <inttypes.h> header file, it is defined as follows:

struct imaxdiv_t { intmax_t quot; intmax_t rem; };

or 

struct imaxdiv_t { intmax_t rem; intmax_t quot; };

Note: This function is equivalent to div_t structure for intmax_t.

Example:

The example below shows the usage of <inttypes.h> imaxdiv_t type.

#include <stdio.h>
#include <inttypes.h>
 
int main (){
  imaxdiv_t result = imaxdiv(50, 17);

  printf("imaxdiv_t(50, 17) gives quotient = %" PRIdMAX " and remainder = %" PRIdMAX "\n",
         result.quot, result.rem);
  
  return 0;
}

The output of the above code will be:

imaxdiv(50, 17) gives quotient = 2 and remainder = 16

❮ C <inttypes.h> Library