Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What does C language %5d mean?
What does C language %5d mean?
In C language, "%5d" means to format parameters by integers. When the number of integer characters is less than 5, a certain number of spaces are formatted to make the sum of the characters used by spaces and integers at least 5.

In C language, "%5d" is generally used for printf function and sprint function. When they format a string, they can specify the format of the string, use some format descriptors starting with "%"to occupy a position inside the format string, and provide the corresponding variables in the following parameter list. Finally, the function will replace the descriptor with the variable in the corresponding position to generate the string that the caller wants.

One of the most common applications of formatting the numeric string sprintf is to print integers into the string. At the same time, you can choose the width, and if it is insufficient, fill in the space to the left: for example, "Sprintf (s,"% 4d% 4d ",123,4567);" The string "1234567" will be generated.

Extended data:

In C language, the common conversion characters are:

1%%: Print the percentage symbol without conversion.

2.%c: Characters are output to the buffer without conversion.

3.%d: Integer is converted to decimal.

4.%f: Double-precision numbers are converted to floating-point numbers.

5.%o: Integer is converted to octal.

6.%s: The string is output to the buffer without conversion.

7.%x: Integer is converted to lowercase hexadecimal.

8.%X: Integer is converted to uppercase hexadecimal.

Baidu encyclopedia-sprint