C Language Length modifiers


Example

The C99 and C11 standards specify the following length modifiers for printf(); their meanings are:

ModifierModifiesApplies to
hhd, i, o, u, x, or Xchar, signed char or unsigned char
hd, i, o, u, x, or Xshort int or unsigned short int
ld, i, o, u, x, or Xlong int or unsigned long int
la, A, e, E, f, F, g, or Gdouble (for compatibility with scanf(); undefined in C90)
lld, i, o, u, x, or Xlong long int or unsigned long long int
jd, i, o, u, x, or Xintmax_t or uintmax_t
zd, i, o, u, x, or Xsize_t or the corresponding signed type (ssize_t in POSIX)
td, i, o, u, x, or Xptrdiff_t or the corresponding unsigned integer type
La, A, e, E, f, F, g, or Glong double

If a length modifier appears with any conversion specifier other than as specified above, the behavior is undefined.

Microsoft specifies some different length modifiers, and explicitly does not support hh, j, z, or t.

ModifierModifiesApplies to
I32d, i, o, x, or X__int32
I32o, u, x, or Xunsigned __int32
I64d, i, o, x, or X__int64
I64o, u, x, or Xunsigned __int64
Id, i, o, x, or Xptrdiff_t (that is, __int32 on 32-bit platforms, __int64 on 64-bit platforms)
Io, u, x, or Xsize_t (that is, unsigned __int32 on 32-bit platforms, unsigned __int64 on 64-bit platforms)
l or La, A, e, E, f, g, or Glong double (In Visual C++, although long double is a distinct type, it has the same internal representation as double.)
l or wc or CWide character with printf and wprintf functions. (An lc, lC, wc or wC type specifier is synonymous with C in printf functions and with c in wprintf functions.)
l or ws, S, or ZWide-character string with printf and wprintf functions. (An ls, lS, ws or wS type specifier is synonymous with S in printf functions and with s in wprintf functions.)

Note that the C, S, and Z conversion specifiers and the I, I32, I64, and w length modifiers are Microsoft extensions. Treating l as a modifier for long double rather than double is different from the standard, though you'll be hard-pressed to spot the difference unless long double has a different representation from double.