Three tables of the printf () function and three printf tables

Source: Internet
Author: User

Three tables of the printf () function and three printf tables

Function prototype:

printf(Control-String, item1, item2, ...);

Table 1 conversion specifiers and printed output as results

Change description

Output

% Floating Point Number, hexadecimal number, and p-Note (C99)
% Floating Point Number, hexadecimal number, and P-Note (C99)
% C One character
% D Signed decimal integer
% E Floating Point Number, e-memory
% E Floating Point Number, E-memory
% F Floating Point, decimal notation
% G % F or % e is automatically selected based on different values. % Eformat used when the exponent is less than-4 or greater than or equal to the precision
% G % F or % E is automatically selected based on different values. % Eformat used when the exponent is less than-4 or greater than or equal to the precision
% I Signed decimal INTEGER (same as % d)
% O Unsigned octal integer
% P Pointer
% S String
% U Unsigned decimal integer
% X Use an unsigned hexadecimal integer of the hexadecimal number 0f
% X Use an unsigned hexadecimal integer of the hexadecimal number 0F
% Print a percent sign


Table 2 printf () Modifier

Modifier

Yi

Flag The five signs (-, +, space, #, and 0) are described in the third part of the table. You can use zero or multiple signs.
Digit (s) The minimum value of the field width. If this field cannot contain the number or string to be printed, the system uses a wider field.
Example: "% 4d"
. Digit (s) Precision. For % e, % E, and % f conversion, it is the number of digits to be printed on the right of the decimal point. % G and % G are the maximum digits of valid numbers. % S conversion is the maximum number of characters to be printed. Integer Conversion is the minimum number of digits to be printed. If necessary, use the leading zero to reach this number. Only "." indicates that it follows a zero, so %. f is the same as %. 0f. Example: "% 5.2f" prints a floating point number. The field width is 5 Characters and there are two digits after the decimal point.
H Used Together with Integer Conversion instructions to indicate a short int or unsigned short int type value.
Example: "% hu", "% hx", and "% 6.4hd"
Hh Used Together with Integer Conversion instructions to indicate a signed char or unsigned char type value.
Example: "% hhu", "% hhx", and "% 6.4hhd"
J It is used with the Integer Conversion specifier to indicate an intmax_t or uintmax_t value.
Example: "% jd" and "% 8jX"
L Used Together with integer specifiers to indicate a long int or unsigned long int type value.
Example: "% ld" and "% 8lu"
Ll Used Together with integer specifiers to indicate a long int or unsigned long int type value (C99)
Example: "% lld" and "% 8llu"
L It is used with the floating point conversion specifier to indicate a long double value.
Example: "% Lf" and ". 4Le"
T Used together with the Integer Conversion specifier to indicate a ptrdiff_t value (the type corresponding to the difference between the two pointers) (C99)
Example: "% td" and "ti"
Z Used together with the Integer Conversion specifier to indicate a size_t value (type returned by sizeof) (C99)
Example: "% zd" and "zx"

 

Table 3 printf () Flag

Logo

Yi

- The project is left aligned, that is, the project is printed at the start of the field on the left.
Example: "%-20s"
+ If the signed value is positive, the symbol with the plus sign is displayed. If the value is negative, the symbol with the minus sign is displayed.
Example: "% + 6.2f"
(Space) If the signed value is positive, leading spaces (but not symbols) are displayed. If the value is negative, a minus sign is used. + The flag will overwrite the space flag.
Example: "% 6.2f"
# Use an optional Form of conversion instructions. If it is in % o format, it starts with 0. If it is in % x and % X format, it starts with 0x or 0X. For all floating point formats, # ensures that even if no number is specified, it also prints a decimal point character. For % g and % G formats, it prevents trailing zeros from being deleted
Example: "% # o", "% # 8.0f", and "% + # 10.3E"
0 For All numeric formats, use leading zero instead of spaces to fill the field width. If a-flag appears or an integer is specified, the flag is ignored.
Example: "0d" and ". 3f"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.