Symbolic effect
──────────────────────────
%d decimal signed integer
%i Enter an integer that can be a octal number with a leading 0 or a hexadecimal number of 0x
%u decimal unsigned integer
%f floating-point numbers
%s string
%c single character
Value of the%p pointer (memory address)
Floating point numbers in the form of%e exponent
%x, int without symbol in hexadecimal notation
%0 An integer that is unsigned as octal
%g,%g automatically select the appropriate notation
━━━━━━━━━━━━━━━━━━━━━━━━━━
The general form of the format string is:
[logo] [Output minimum width] [. precision] [length] type
The items in square brackets [] are optional. The meaning of the items is described below:
1. The type type character is used to represent the type of output data, and its format character and meaning are shown in the following table:
Format character format character meaning of output type
D output signed integers in decimal form (positive not output symbols)
o Output unsigned integers in eight (no output prefix O)
x output unsigned integer in 16 (do not output prefix ox)
U output unsigned integers in decimal form
F output single, double real numbers in decimal form
E output single and double precision real numbers in exponential form
g to output single and double precision real numbers in shorter output widths of%f%e
C Output Single character
S output string
2. Logo
The symbol character is-, +, #, the space four kinds, its meaning is shown in the following table:
Flag format character flag meaning
-the result is left-aligned, the right blank
+ Output symbol (plus or minus) space output value is positive with a space, negative with minus sign
# has no effect on the C,s,d,u class; for class O, prefix the output. For the X class, prefix the output with 0x; give a decimal point to the E,g,f class when the result has a decimal number
3. Output minimum width
A decimal integer to represent the minimum number of digits for the output. If the actual number is more than the defined width, the actual number of digits is output, if the actual number is less than the defined width, a space or 0 is filled.
4. Precision
The precision format character is "." The beginning followed by a decimal integer. The meaning of this item is: If the number is output, the number of digits, if the output is a character, the number of output characters, if the actual number of digits is greater than the defined number of precision, then truncate the more parts.
5. Length
The length format character is h,l Two, h means to output by the short integer, L represents the output by the long integer quantity
Description
(1) The maximum field width can be inserted between "%" and the letter.
For example:%3d represents an output 3-bit integer and is not 3-bit right-aligned.
%9.2F represents a floating-point number with an output field width of 9, where the decimal digit is 2, the integer digit is 6, the dot is one digit, and the 9-bit right alignment is not enough.
%8s represents a 8-character string that is not 8 words Fu Yi aligned.
If the length of the string, or the integer number of digits exceeds the field width of the description, it will be output at its actual length.
However, for floating point numbers, if the integer partial digits exceed the indicated integer digit width, the actual integer digits are output; if the fractional digit number exceeds the indicated decimal width, the output is rounded by the width of the description.
In addition, if you want to add some 0 before the output value, you should add a 0 to the presence width.
For example,%04d indicates that when outputting a value less than 4 digits, the front complement of 0 will make the total width 4 bits.
If you use floating-point numbers to represent the output format for characters or integers, the digits after the decimal point represent the maximum width, and the digits before the decimal point represent the minimum width.
For example,%6.9s represents a string that is not less than 6 and not greater than 9. If greater than 9, the contents of the 9th character will be deleted.
(2), can be in "%" and letters between the lowercase letter L, indicating that the output is a long type number.
For example:%ld indicates output long integer,%LF represents output double floating-point number
(3), you can control the output to the left or right alignment, that is, "%" and letters to add a "-" to indicate that the output is left-aligned, otherwise the right alignment.
For example:%-7d represents an output 7-bit integer left-aligned,%-10s indicates that the output is 10 characters left-aligns aligned
(4) You can add a * number between the formatted character and% to skip the corresponding input data.
For example: scanf ("%d%*d%d", &a,&b) when input 10 20 30 o'clock, the values of A and B are 10 and 30 respectively.