int printf(const char *format,[argument]);
format
The format of parameter output, the definition format is: %[flags][width ][.perc][F|N|h|l]type
Specifies the data output method, as follows:
1. The meaning of type is as follows:
d Signed decimal integer
i Signed decimal integer
o Unsigned octal integer
u Unsigned decimal integer< /p>
x Unsigned hexadecimal number, expressed in lowercase abcdef
X Unsigned hexadecimal number, expressed in uppercase ABCDEF
f Float Point number
E/e Floating point number in scientific notation format
g Use %f and %e to express the shortest total number of digits to represent floating point number G. Same as g format , but expressed as an exponent
c single character
s string
S wchar_t character (wide character) type string
% Display the percent sign itself
p Display a pointer, the near pointer is represented as: XXXX
The far pointer is represented as: XXXX: YYYY
n The connected parameter should be A pointer that stores the number of written characters
2.flags specifies the output format. The values ??and meanings are as follows:
No right alignment, padded with 0s and spaces on the left
- Left-justified, padded with spaces on the right
+ Add the symbol + or - before the number
0 Add 0 in front of the output until the specified column width is filled (Cannot be used together with -)
When the space output value is positive, it is preceded by a space, and when it is negative, it is preceded by a minus sign
# When type=c,s,d,i, There is no effect when u
When type=o,x,X, add '0', "0x", "0X" in front of the value respectively
type=e,E,f When type=g,G, the decimal point is always displayed except when the value is 0
3.width is used to control the width of the displayed value, and the value is The meaning is as follows
n(n=1,2,3...) The width is at least n bits, which is not enough to fill with spaces
0n(n=1,2,3.. .) The width is at least n digits, and the left side is filled with 0 if it is not enough
* In the format list, the next parameter is width
4.prec is used to control the number of digits after the decimal point, take The values ??and meanings are as follows:
No display according to the default precision
0 When type=d,i,o,u,x, there is no effect
type =e,E,f, no decimal point is displayed
n(n=1,2,3...) The maximum number of decimal places expressed when type=e,E,f
type=other, indicating the maximum width of the display
.* In the format list, the next parameter is still width
5.F|N|h|l indicates whether the pointer is Whether the far pointer or integer is a long integer
F far pointer
n near pointer
h short integer or single-precision floating point number
l 长整数或双精度浮点数
以上内容参考:/view/410546.htm
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
________________________________________________________________
重点看 In the second line, [h] indicates that h is optional, but type is required. So it is wrong to just write h, because there is no type. And u is a type, so it’s OK.
It’s just a rule of C language, there’s no reason why haha.