As it seems most C programmers are too lazy to look this up in the (freely available) authoritative documentation, here is the list of standard integer types from the ISO/IEC C99, and their format strings.
All types are defined in <stdint.h>
while the format string macros are defined <inttypes.h>
(which includes <stdint.h> by the way).
| Type | Printing format string | ||||
|---|---|---|---|---|---|
| Unsigned | Signed | Decimal | Signed decimal | Octal | Hexadecimal |
unsigned char |
char |
"%hhu" |
"%hhi" or "%hhd" |
"%hho" |
"%hhx" or "%hhX" |
unsigned short |
short |
"%hu" |
"%hi" or "%hd" |
"%ho" |
"%hx" or "%hX" |
unsigned |
int |
"%u" |
"%i" or "%d" |
"%o" |
"%x" or "%X" |
unsigned long |
long |
"%lu" |
"%li" or "%ld" |
"%lo" |
"%lx" or "%lX" |
unsigned long long |
long long |
"%llu" |
"%lli" or "%lld" |
"%llo" |
"%llx" or "%llX" |
uint8_t |
int8_t |
"%"PRIu8 |
"%"PRIi8 or "%"PRId8 |
"%"PRIo8 |
"%"PRIx8 or "%"PRIX8 |
uint16_t |
int16_t |
"%"PRIu16 |
"%"PRIi16 or "%"PRId16 |
"%"PRIo16 |
"%"PRIx16 or "%"PRIX16 |
uint32_t |
int32_t |
"%"PRIu32 |
"%"PRIi32 or "%"PRId32 |
"%"PRIo32 |
"%"PRIx32 or "%"PRIX32 |
uint64_t |
int64_t |
"%"PRIu64 |
"%"PRIi64 or "%"PRId64 |
"%"PRIo64 |
"%"PRIx64 or "%"PRIX64 |
| Not available | ptrdiff_t |
"%tu" |
"%ti" or "%td" |
"%to" |
"%tx" or "%tx" |
size_t |
ssize_t |
"%zu" |
"%zi" or "%zd" |
"%zo" |
"%zx" or "%zx" |
uintmax_t |
intmax_t |
"%ju" |
"%ji" or "%jd" |
"%jo" |
"%jx" or "%jx" |
uintptr_t |
intptr_t |
Not available.
Use/Cast to (u)intmax_t instead. |
|||
Scanning format strings (for *scanf() functions) are identical
to printing format strings, with the exception that macros are called
SCN* instead of PRI*.