%3d means outputting a 3-digit integer, which is not enough to be right-aligned. %2d means outputting a 2-digit integer, which is not enough to be right-aligned.
Formatting specified characters, starting with "%", followed by one or several specified characters, are used to determine the output content format. Insert a number between the "%" and the letter to indicate the maximum field width.
For example, %9.2f means that the output field width is a floating point number of 9, in which the decimal place is 2, the integer place is 7, the decimal point occupies one place, and it is not enough for 9 digits to be right-aligned.
%8s means outputting a string of 8 characters, which is not enough to right-align. If the length of the string or the number of integer digits exceeds the specified field width, the actual length will be output.
Extended information:
The printf() function is generally used to output messages in a specified format to standard output devices. This function is often used when writing steps. The calling format of the printf() function is: printf("
The formatted string includes two parts: one part is normal characters, and these characters It will be output as is; the other part is the formatting specification characters, starting with "%", followed by one or several specification characters, which are used to determine the output content format. ?
The parameter table is a series of parameters that need to be output. The number must be as many as the number of output parameters specified by the formatted string. Each parameter is separated by "," and the order Correspond one by one, otherwise unexpected mistakes will occur.
Note: The function printf pushes the stack from right to left, then puts the first read on the bottom of the stack, and the last read on the top of the stack. The processing starts from the top of the stack, so what we see The result is that processing starts from the right.
Reference materials:
Baidu Encyclopedia-printf