Format the specified characters, starting with "%",followed by one or more specified characters to determine the output content format. Inserting a number between "%"and letters indicates the maximum field width.
For example, %9.2f represents a floating-point number with an output field width of 9, where the decimal place is 2, the integer place is 7, and the decimal point occupies one place, which is not enough to align 9 places to the right.
%8s means to output an 8-character string, which is not enough for right alignment. If the length or integer digits of the string exceed the specified field width, it will be output according to its actual length.
Extended data:
The printf () function is usually used to output messages to standard output devices in a specified style. This function is often used when writing steps. The appropriation mode of printf () function is: printf (",< parameter table >);
Among them, the stylized character string includes two parts: one part is a normal character, which will be output as it is; The other part is stylized designated characters, starting with "%"followed by one or several designated characters, which are used to determine the style of the output content. ?
Parameter table is a series of parameters to be output, and the number of parameters must be as many as the number of output parameters described in the programmed string. Parameters are separated by ",",and the order corresponds to each other, otherwise unexpected errors will occur.
Note: the function printf presses the stack from right to left, and then puts the first reading at the bottom of the stack and the last reading at the top of the stack. Processing starts from the top of the stack, so what we see is that processing starts from the right.
References:
Baidu encyclopedia -printf