printf format specifier#
general
%[flags][width][.precision][length]specifier
flag#
Flag |
Description |
---|---|
|
Left-justify: The result is left-aligned within the specified field width. By default, it is right-aligned. |
|
Sign: The result of a signed conversion will always begin with a sign ( |
|
Space: If the first character of a signed conversion is not a sign, a space is prepended. This is ignored if the |
|
Alternate Form: For |
|
Zero-padding: For numeric types, the output is padded with leading zeros instead of spaces to fill the field width. This is ignored if the |
width#
The width sub-specifier sets the minimum number of characters to be printed.
Width |
Description |
---|---|
|
A non-negative integer specifying the minimum number of characters to print. If the printed value is shorter, it is padded with spaces (or zeros if the |
|
The width is not specified in the format string itself, but as an additional integer argument preceding the argument to be formatted. |
precision#
Precision |
Description |
---|---|
|
For integer specifiers ( |
|
The precision is not specified in the format string itself, but as an additional integer argument preceding the argument to be formatted. |
length#
Modifier |
For Integer Specifiers ( |
For Floating-Point Specifiers ( |
---|---|---|
|
|
- |
|
|
- |
|
|
- |
|
|
- |
|
- |
|
|
|
- |
|
|
- |
|
|
- |
specifier#
Specifier |
Data Type |
Output Format |
---|---|---|
|
|
A single character. |
|
|
A string of characters. |
|
|
Signed decimal integer. |
|
|
Unsigned decimal integer. |
|
|
Unsigned octal integer. |
|
|
Unsigned hexadecimal integer (lowercase letters). |
|
|
Unsigned hexadecimal integer (uppercase letters). |
|
|
Decimal floating-point number. |
|
|
Decimal floating-point number (uppercase ‘INF’ and ‘NAN’). |
|
|
Scientific notation (lowercase ‘e’). |
|
|
Scientific notation (uppercase ‘E’). |
|
|
Uses the shorter of |
|
|
Uses the shorter of |
|
|
Hexadecimal floating-point number (lowercase ‘p’). |
|
|
Hexadecimal floating-point number (uppercase ‘P’). |
|
|
Pointer address. |
|
|
The number of characters written so far is stored in the integer pointed to by the argument. Nothing is printed. |
|
None |
A literal ‘%’ character is printed. |