Size Specification

In a format specification, the fourth field is an argument length modifier for the conversion specifier. The size field prefixes to the type field—h, l, w, I, I32, I64, and ll—specify the "size" of the corresponding argument—long or short, 32- or 64-bit, single-byte character or wide character—depending on the conversion specifier that they modify. These size prefixes are used with type characters in the printf and wprintf families of functions to specify the interpretation of argument lengths, as shown in the following table. The size field is optional for some argument types. When no size prefix is specified, integer arguments are coerced to int type, and floating-point arguments are coerced to double. On 64-bit systems, an int is a 32-bit value; therefore, 64-bit integers are truncated when they are formatted for output unless a size prefix of ll or I64 is used. On 32-bit systems, only the first 32 bits of a 64-bit integer argument are consumed by the formatter, and subsequent conversions in the format string are incorrect, unless a size prefix of ll or I64 is used.

Note

The I, I32, and I64 length modifier prefixes are Microsoft extensions and are not ANSI-compatible. The h prefix when it's used with data of type char, the w prefix when it's used with data of type wchar_t, and the l prefix when it's used with data of type double are Microsoft extensions. The hh, j, z, and t length prefixes are not supported.

Size Prefixes for printf and wprintf Format-Type Specifiers

To specify

Use prefix

With type specifier

long int

l (lowercase L)

d, i, o, x, or X

long unsigned int

l

o, u, x, or X

long long

ll

d, i, o, x, or X

short int

h

d, i, o, x, or X

short unsigned int

h

o, u, x, or X

__int32

I32

d, i, o, x, or X

unsigned __int32

I32

o, u, x, or X

__int64

I64

d, i, o, x, or X

unsigned __int64

I64

o, u, x, or X

ptrdiff_t (that is, __int32 on 32-bit platforms, __int64 on 64-bit platforms)

I

d, i, o, x, or X

size_t (that is, unsigned __int32 on 32-bit platforms, unsigned __int64 on 64-bit platforms)

I

o, u, x, or X

long double (In Visual C++, although long double is a distinct type, it has the same internal representation as double.)

l or L

a, A, e, E, f, g, or G

Single-byte character with printf and wprintf functions. (An hc or hC type specifier is synonymous with c in printf functions and with C in wprintf functions.)

h

c or C

Wide 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 w

c or C

Single-byte character string with printf and wprintf functions. (An hs or hS type specifier is synonymous with s in printf functions and with S in wprintf functions.)

h

s, S, or Z

Wide-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.)

l or w

s, S, or Z

See Also

Reference

printf, _printf_l, wprintf, _wprintf_l

Format Specification Syntax: printf and wprintf Functions

Flag Directives

printf Width Specification

Precision Specification

printf Type Field Characters