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.
Compile requirement:
In the following list all macros with the suffix MAX or 64 require long long to be available.
PRId8 | PRId16 | PRId32 | PRId64 |
PRIdLEAST8 | PRIdLEAST16 | PRIdLEAST32 | PRIdLEAST64 |
PRIdFAST8 | PRIdFAST16 | PRIdFAST32 | PRIdFAST64 |
PRIdMAX | |||
PRIdPTR | |||
PRIi8 | PRIi16 | PRIi32 | PRIi64 |
PRIiLEAST8 | PRIiLEAST16 | PRIiLEAST32 | PRIiLEAST64 |
PRIiFAST8 | PRIiFAST16 | PRIiFAST32 | PRIiFAST64 |
PRIiMAX | |||
PRIiPTR |
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:
PRIo8 | PRIo16 | PRIo32 | PRIo64 |
PRIoLEAST8 | PRIoLEAST16 | PRIoLEAST32 | PRIoLEAST64 |
PRIoFAST8 | PRIoFAST16 | PRIoFAST32 | PRIoFAST64 |
PRIoMAX | |||
PRIoPTR | |||
PRIu8 | PRIu16 | PRIu32 | PRIu64 |
PRIuLEAST8 | PRIuLEAST16 | PRIuLEAST32 | PRIuLEAST64 |
PRIuFAST8 | PRIuFAST16 | PRIuFAST32 | PRIuFAST64 |
PRIuMAX | |||
PRIuPTR | |||
PRIx8 | PRIx16 | PRIx32 | PRIx64 |
PRIxLEAST8 | PRIxLEAST16 | PRIxLEAST32 | PRIxLEAST64 |
PRIxFAST8 | PRIxFAST16 | PRIxFAST32 | PRIxFAST64 |
PRIxMAX | |||
PRIxPTR | |||
PRIX8 | PRIX16 | PRIX32 | PRIX64 |
PRIXLEAST8 | PRIXLEAST16 | PRIXLEAST32 | PRIXLEAST64 |
PRIXFAST8 | PRIXFAST16 | PRIXFAST32 | PRIXFAST64 |
PRIXMAX | |||
PRIXPTR |
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:
SCNd8 | SCNd16 | SCNd32 | SCNd64 |
SCNdLEAST8 | SCNdLEAST16 | SCNdLEAST32 | SCNdLEAST64 |
SCNdFAST8 | SCNdFAST16 | SCNdFAST32 | SCNdFAST64 |
SCNdMAX | |||
SCNdPTR | |||
SCNi8 | SCNi16 | SCNi32 | SCNi64 |
SCNiLEAST8 | SCNiLEAST16 | SCNiLEAST32 | SCNiLEAST64 |
SCNiFAST8 | SCNiFAST16 | SCNiFAST32 | SCNiFAST64 |
SCNiMAX | |||
SCNiPTR |
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:
SCNo8 | SCNo16 | SCNo32 | SCNo64 |
SCNoLEAST8 | SCNoLEAST16 | SCNoLEAST32 | SCNoLEAST64 |
SCNoFAST8 | SCNoFAST16 | SCNoFAST32 | SCNoFAST64 |
SCNoMAX | |||
SCNoPTR | |||
SCNu8 | SCNu16 | SCNu32 | SCNu64 |
SCNuLEAST8 | SCNuLEAST16 | SCNuLEAST32 | SCNuLEAST64 |
SCNuFAST8 | SCNuFAST16 | SCNuFAST32 | SCNuFAST64 |
SCNuMAX | |||
SCNuPTR | |||
SCNx8 | SCNx16 | SCNx32 | SCNx64 |
SCNxLEAST8 | SCNxLEAST16 | SCNxLEAST32 | SCNxLEAST64 |
SCNxFAST8 | SCNxFAST16 | SCNxFAST32 | SCNxFAST64 |
SCNxMAX | |||
SCNxPTR |
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