In a format specification, the type character is a conversion specifier that specifies whether the corresponding argument is to be interpreted as a character, a string, a pointer, an integer, or a floating-point number. The type character is the only required format specification field, and it appears after any optional fields.
Type Character | Argument | Output format |
---|---|---|
c | int | Single character. |
d | int | Signed decimal integer. |
i | int | Signed decimal integer. |
o | int | Unsigned octal integer. |
u | int | Unsigned decimal integer. |
x | int | Unsigned hexadecimal integer; uses "abcdef." |
X | int | Unsigned hexadecimal integer; uses "ABCDEF." |
e | double | Signed value that has the form [–]d.dddd e [sign]dd[d] where d is one decimal digit, dddd is one or more decimal digits, dd[d] is two or three decimal digits depending on the output format and size of the exponent, and sign is + or –. |
E | double | Identical to the e format except that E rather than e introduces the exponent. |
f | double | Signed value that has the form [–]dddd.dddd, where dddd is one or more decimal digits. The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision. |
g | double | Signed values are displayed in f or e format, whichever is more compact for the given value and precision. The e format is used only when the exponent of the value is less than –4 or greater than or equal to the precision argument. Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it. |
G | double | Identical to the g format, except that E, rather than e, introduces the exponent (where appropriate). |
s | string | When used with printf functions, specifies a single-byte or multi-byte character string; when used with wprintf functions, specifies a wide-character string. Characters are displayed up to the first null character or until the precision value is reached. |