Printf output function, printf output

Source: Internet
Author: User

Printf output function, printf output

The printf function is called the format output function.

Format:

Printf (const char * _ Format ,...)

Printf ("format control string", output table column)
The format control string is used to specify the output format. The format control string can be a format string or a non-format string. The format string is a string starting with "%". It is followed by characters in different formats to indicate the type, format, length, and decimal places of the output data. For example:

  • "% D" indicates output in decimal integer;
  • "% Ld" indicates the output is a long integer in decimal format;
  • "% C" indicates output based on bytes.

 

1) Type
The type character is used to indicate the type of output data. Its format characters and meanings are shown in the following table:

Format characters Meaning
D Outputs signed integers in decimal form (positive numbers do not output symbols)
O Output an unsigned integer in octal format (no prefix 0 is output)
X, X Output an unsigned integer in hexadecimal format (the Ox prefix is not output)
U Returns an unsigned integer in decimal format.
F Output Single and Double Precision Real Numbers in decimal form
E, E Output Single and Double Precision Real Numbers in exponential form
G, G Output Single and Double precision real numbers with a shorter output width in % f or % e
C Output Single Character
S Output string
 

2) Flag
The following table lists the four types of Logo characters:-, +, #, and space:

 

 

Logo Meaning
- The result is left aligned with a space on the right.
+ Output symbol (positive or negative)
Space When the output value is positive, it is preceded by a space.
# It has no effect on Class c, s, d, and u;
For the o class, add the prefix o to the output;
Add the prefix 0x to the output of Class x;
The decimal point is given for Class e, g, and f when the result has decimal places.

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.