| Conversion instructions |
Output |
| %a,%a |
Floating-point numbers, hexadecimal numbers, and P-count methods (C99) |
| %c |
A character |
| %d |
Signed decimal number |
| %e,%e |
Floating-point number, E-counting method |
| %f |
Floating-point numbers, decimal notation |
| %g,%g |
Automatically select the%f or%e,%e format when the exponent is less than-4 or greater than or equal to the precision based on the value |
| %i |
Signed decimal integer (same as%d) |
| %o |
unsigned octal integer |
| %p |
Pointer |
| %s |
String |
| %u |
unsigned decimal number |
| %x,%x |
Unsigned hexadecimal integer with hexadecimal number 0f |
| %% |
Print a percent semicolon |
prinf () modifier
| Modifier |
Significance |
| Sign |
The five flags are described in a later table and can be used with 0 or more flags Example: "%-10d" |
| Digit (s) |
The minimum value of the field width. If the field cannot hold the number or string you want to print, the system uses a wider field Example: "%4d", "%10s" |
| . Digit (s) |
Precision. For%e,%e and%f conversions, the number of digits that will be printed on the right side of the decimal point. For%g and%g conversions, the maximum number of digits for a valid number. For the%s conversion, is the maximum number of characters that will be printed. For integer conversions, is the minimum number of digits that will be printed. If necessary, use leading zeros to reach the number of digits. Use only "." Followed by a 0, so%.f and%.0f are the same Example: "%5.2f" means printing a floating-point number with a field width of 5 characters and two digits after a decimal point |
| H |
Used with integer conversion specifiers to denote a short int or unsigned short int type value Example: "%hu", "%hx", "%6.4HD" |
| hh |
Used with the certificate conversion specifier to represent a signed char or unsigned char type value |
| J |
Used with integer conversion specifiers to represent a intmax_t or uintmax_t value Example: "%jd", "%8JX" |
| L |
Used in conjunction with integer conversion specifiers to represent a long int or unsigned long int type value |
| ll |
Used with integer conversion specifiers to represent a long long int or unsigned long long int value (C99) Example: "%lld", "%8llu" |
| L |
Used with the floating-point conversion specifier to represent a long double value Example: "%lf", "%10.4le" |
| T |
Used with integer conversion specifiers to represent a ptrdiff_t value (the type corresponding to the difference between two pointers) (C99) Example: "%td", "%1ti" |
| Z |
Used with integer conversion specifiers to represent a size_t value (the type that sizeof returns) (C99) Example: "%zd", "%12ZX" |
The mark of printf ()
| Sign |
Significance |
| - |
Item is left aligned, that is, the item is printed on the left side of the field Example: "%-20s" |
| + |
If the signed value is positive, a symbol with a plus sign is displayed, or a symbol with a minus sign if it is negative Example: "%+6.2f" |
| Spaces |
If the signed value is positive, the display is preceded by a leading space (but not the symbol) and, if negative, with a minus sign. The + flag will overwrite the space mark Example: "% 6.2f" |
| # |
Use an optional form of the conversion description. If the format is%o, start at 0 and start at 0x or 0X if%x and%xgeshi. For all floating-point forms, #保证了即使不跟任何数字, a decimal character is also printed. For%g and%g formats, It prevents trailing 0 from being deleted Example: "% #o", "% #8.0f", "%+ #10.3E" |
| 0 |
For all number formats, fill the field width with leading zeros instead of spaces. If the-flag is present or the precision is specified (for integers), the flag is ignored Example: "%010d", "%08.3f", "%02x" |
C-language printf formatted output modifier