Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Visual Studio 2017 Documentation. 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-bit 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, the formatter consumes integer arguments—for example, signed or unsigned char, short, int, long, and enumeration types—as 32-bit int types, and floating-point arguments are consumed as 64-bit double types. This matches the default argument promotion rules for variable argument lists. For more information about argument promotion, see Ellipses and Default Arguments. On both 32-bit and 64-bit systems, the format specification of a 64-bit integer argument must include a size prefix of ll or I64. Otherwise, the behavior of the formatter is undefined.
Some types are different sizes in 32-bit and 64-bit code. For example, size_t is 32 bits long in code compiled for x86, and 64 bits in code compiled for x64. To create platform-agnostic formatting code for variable-width types, you can use a variable-width argument length modifier. Alternatively, use a 64-bit argument length modifier and explicitly promote the variable-width argument type to 64 bits. The Microsoft-specific I argument length modifier handles variable-width integer arguments.
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, orX | 
| long unsigned int | l | o,u,x, orX | 
| long long | ll | d,i,o,x, orX | 
| short int | h | d,i,o,x, orX | 
| short unsigned int | h | o,u,x, orX | 
| __int32 | I32 | d,i,o,x, orX | 
| unsigned __int32 | I32 | o,u,x, orX | 
| __int64 | I64 | d,i,o,x, orX | 
| unsigned __int64 | I64 | o,u,x, orX | 
| ptrdiff_t(that is,__int32on 32-bit platforms,__int64on 64-bit platforms) | I | d,i,o,x, orX | 
| size_t(that is,unsigned __int32on 32-bit platforms,unsigned __int64on 64-bit platforms) | I | o,u,x, orX | 
| long double(In Visual C++, althoughlong doubleis a distinct type, it has the same internal representation asdouble.) | lorL | a,A,e,E,f,g, orG | 
| Single-byte character with printfandwprintffunctions. (AnhcorhCtype specifier is synonymous withcinprintffunctions and withCinwprintffunctions.) | h | corC | 
| Wide character with printfandwprintffunctions. (Anlc,lC,wcorwCtype specifier is synonymous withCinprintffunctions and withcinwprintffunctions.) | lorw | corC | 
| Single-byte character string with printfandwprintffunctions. (AnhsorhStype specifier is synonymous withsinprintffunctions and withSinwprintffunctions.) | h | s,S, orZ | 
| Wide-character string with printfandwprintffunctions. (Anls,lS,wsorwStype specifier is synonymous withSinprintffunctions and withsinwprintffunctions.) | lorw | s,S, orZ | 
See Also
printf, _printf_l, wprintf, _wprintf_l
Format Specification Syntax: printf and wprintf Functions
Flag Directives
printf Width Specification
Precision Specification
printf Type Field Characters