inttypes.h — I/O format of integer types

The following macros are defined in inttypes.h. Each expands to a character string literal containing a conversion specifier which can be modified by a length modifier that can be used in the format argument of a formatted input/output function when converting the corresponding integer type. These macros have the general form of PRI (character string literals for the fprintf() and fwprintf() family of functions) or SCN (character string literals for the fscanf() and fwscanf() family of functions), followed by the conversion specifier, followed by a name corresponding to a similar type name in <inttypes.h>. In these names, the suffix number represents the width of the type. For example, PRIdFAST32 can be used in a format string to print the value of an integer of type int_fast32_t.

This header defines the type imaxdiv_t.
Note: Requires long long to be available.
imaxdiv_t is a structure type that is the type of the value returned by the imaxdiv() function. It is functionally equivalent to lldiv_t.

Compile requirement:

In the following list all macros with the suffix MAX or 64 require long long to be available.

Example

#define _ISOC99_SOURCE
#include <inttypes.h>      
#include <stdio.h> 
int main(void)                                             
{                                                          

int8_t i =  40; 
printf("Demonstrating the use of the following macros:\n");
printf("Using PRId8, the printed value of 40 "                  
"is  %" PRId8"\n", i);                                    
printf("Using PRIiFAST8, the printed value of 40 "               
"is  %" PRIiFAST8"\n", i);                                 
printf("Using PRIoLEAST8, the printed value of 40 "              
"is  %" PRIoLEAST8 "\n", i);                               
return 0;                                                  
}                          


Output:

Demonstrating the use of the following macros:  
Using PRId8, the printed value of 40 is  40     
Using PRIiFAST8, the printed value of 40 is  40 
Using PRIoLEAST8, the printed value of 40 is  50

Compile requirement:

In the following list all macros with the suffix MAX or 64 require long long to be available.

Macros for fprintf family for unsigned integers:

Example

#define _ISOC99_SOURCE
#include <inttypes.h>      
#include <stdio.h> 

int main(void)                                             
{                                                          
uint32_t i =  24000;                                       
printf("Demonstrating the use of the following macros:\n");
printf("Using PRIuPTR, the address of the variable "           
"is  %" PRIuPTR "\n", i);                                 
printf("Using PRIXFAST32, the printed value of 24000 "     
"is  %" PRIXFAST32"\n", i);                                
printf("Using PRIxLEAST32, the printed value of 24000 "    
"is  %" PRIxLEAST32 "\n", i);                              
return 0;                                                  
}                                                         
                     
                                      

Output:

Demonstrating the use of the following macros:        
Using PRIuPTR, the address of the variable is  538874544  
Using PRIXFAST32, the printed value of 24000 is  5DC0 
Using PRIxLEAST32, the printed value of 24000 is  5dc0

Compile requirement:

In the following list all macros with the suffix MAX or 64 require long long to be available.

Macros for fscanf family for signed integers:

Example

#define _ISOC99_SOURCE
#include <inttypes.h>      
#include <stdio.h> 

int main(void)
{
    int32_t i;
    printf("Enter decimal value ");
    scanf("%" SCNdFAST32, i);
    printf("Print result: %" PRIdFAST32 "\n", i);
   return 0;
}

Output:

Enter decimal value 23
Print result: 23

Compile requirement:

In the following list all macros with the suffix MAX or 64 require long long to be available.

Macros for fscanf family for signed integers:

Example

#define _ISOC99_SOURCE
#include <inttypes.h>      
#include <stdio.h> 

int main(void)                                   
{                                                
    intmax_t i;                                  
    printf("Enter hex value ");                  
    scanf("%" SCNxMAX, i);                      
    printf("Print result: %020" PRIxMAX "\n", i);
    return 0;                                    
}                                                

Output :

Enter hex value 0x32              
Print result: 00000000000000000032