A format modifier is the optional part of a printf format specification that selects the corresponding argument’s exact type or width. In "%ld", l selects a long integer; the final specifier still selects decimal conversion. section 8.4.4
Matching modifiers to arguments
long count = 42; printf("%ld\n", count); Here, l identifies the long integer argument, while d requests decimal output. Other examples include "%zu" for size_t, "%jd" for intmax_t, and "%Lf" for long double. section 8.4.4
Common integer and floating-point modifiers include:
- hh selects char types; h selects short types; no modifier selects signed or unsigned int. section 8.4.4
- l and ll select long and long long integer types. section 8.4.4
- j, z, and t select intmax_t, size_t, and ptrdiff_t. section 8.4.4
- L selects long double; float arguments are first converted to double. section 8.4.4
Table 8.12 Format modifiers for printf and similar functions. float arguments are first converted to double.
| Modifier | Type | Conversion |
"L" |
long double |
Floating point |
"hh" |
char types |
Integer |
"h" |
short types |
Integer |
"" |
signed, unsigned |
Integer |
"l" |
long integer types |
Integer |
"ll" |
long long integer types |
Integer |
"j" |
intmax_t, uintmax_t |
Integer |
"z" |
size_t |
Integer |
"t" |
ptrdiff_t |
Integer |
| Since C23, for 𝑁, usually 8, 16, 32, 64, or 128 | ||
"w𝑁" |
uint𝑁_t, int𝑁_t, uint_least𝑁_t, or int_least𝑁_t for 𝑁, usually 8, 16, 32, 64, or 128 |
Integer |
"wf𝑁" |
uint_fast𝑁_t or int_fast𝑁_t |
Integer |
Use the modifier table as a lookup for matching printf conversions to standard C types, including C23 width-specific integer types. section 8.4.4
