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.
|