C integer types

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
Decimal Octal Hexadecimal
unsigned char "%hhu" "%hho" "%hhx" or "%hhX"
signed char "%hhi" or "%hhd"
unsigned short "%hu" "%ho" "%hx" or "%hX"
short "%hi" or "%hd"
unsigned "%u" "%o" "%x" or "%X"
int "%i" or "%d"
unsigned long "%lu" "%lo" "%lx" or "%lX"
long "%li" or "%ld"
unsigned long long "%llu" "%llo" "%llx" or "%llX"
long long "%lli" or "%lld"
uint8_t "%"PRIu8 "%"PRIo8 "%"PRIx8 or "%"PRIX8
int8_t "%"PRIi8 or "%"PRId8
uint16_t "%"PRIu16 "%"PRIo16 "%"PRIx16 or "%"PRIX16
int16_t "%"PRIi16 or "%"PRId16
uint32_t "%"PRIu32 "%"PRIo32 "%"PRIx32 or "%"PRIX32
int32_t "%"PRIi32 or "%"PRId32
uint64_t "%"PRIu64 "%"PRIo64 "%"PRIx64 or "%"PRIX64
int64_t "%"PRIi64 or "%"PRId64
ptrdiff_t "%ti" or "%td"
size_t "%zu" "%zo" "%zx" or "%zx"
ssize_t "%zi" or "%zd"
uintmax_t "%ju" "%jo" "%jx" or "%jx"
intmax_t "%ji" or "%jd"
uintptr_t Not available. Use/Cast to (u)intmax_t instead.
intptr_t

Scanning format strings (for *scanf() functions) are identical to printing format strings, with the exception that macros are called SCN* instead of PRI*.