C++ Standard Library C++ STL Library

C++ <cinttypes> - imaxdiv_t structure type



The C++ <cinttypes> 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 <cinttypes> 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 <cinttypes> imaxdiv_t type.

#include <iostream>
#include <cinttypes>
using namespace std;
 
int main (){
  imaxdiv_t result = imaxdiv(50, 17);

  cout<<"imaxdiv(50, 17) gives quotient = "<<
      result.quot<<" and remainder = "<< 
      result.rem<<"\n";
  
  return 0;
}

The output of the above code will be:

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

❮ C++ <cinttypes> Library