Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What does printf mean?
What does printf mean?
① ① The ①①printf () function is a print format function, which is generally used to output information to a standard output device in a specified format.

Format output, which is a function to generate print format in C language (defined in stdio.h). Used to output characters to terminals (monitors, consoles, etc.). ). Format control consists of text to be output and data format description. In addition to letters, numbers, spaces and some numerical symbols, the text to be output can also use some escape characters to express special meanings.

Simply put, if you use this function correctly in a program, you can output what you need when the program is running.

② The ②②printf function is a standard library function, and its function prototype is in the header file "stdio.h". However, as a special case, you don't need to include the stdio.h file before using the printf function.

The calling format of the printf () function is: printf (",< parameter table >). The formatting string is used to specify the output format. Format control strings can be composed of format strings and unformatted strings.

A format string is a string that begins with%, followed by various format characters to explain the type, form, length, decimal places, etc. Output data. For example, "%d" means decimal integer output, "%ld" means decimal long integer output, "%C" means character output, etc.

Unformatted strings are printed as they are when output, which plays a prompt role in the display. Each output item is given in the output table column, which requires that the format string and each output item should correspond to each other in number and type. ?

(1) Here is a short function that can be run in a code block and is easy to understand:

void main()

{

int a=88,b = 89

printf("%d %d\n ",a,b);

printf("%d,%d\n ",a,b);

printf("%C,%C\n ",a,b);

printf("a=%d,b=%d ",a,b);

}

The running results are shown in the figure.

In this example, the values of a and b are output four times, but the output results are different because of the different format control strings.

In the format control string of the output statement on the fourth line, a space (unformatted character) is added between the two format strings %d, so there is a space between the output A and B values.

The unformatted character comma is added to the format control string of the printf statement in the fifth line, so a comma is added between the output A and B values.

The format string of the sixth line requires the values of a and b to be output in character form.

In the seventh line, an unformatted string is added to prompt the output result. ?

1.Type Type character is used to indicate the type of output data, and its format characters and meanings are shown in the following table:?

Format character representing output type: What does format character mean?

D: output signed integers in decimal form (positive numbers do not output symbols)?

O: output unsigned integers in octal form (output without prefix o)?

X: output unsigned integer in hexadecimal form (not output prefix OX)?

U: Output unsigned integers in decimal form?

F: Output single-precision and double-precision real numbers in decimal form?

E: output single-precision and double-precision real numbers in exponential form?

G: Output single-precision and double-precision real numbers with shorter output width in %f%e?

C: output a single character?

S: output string?

Reference: printf- Baidu encyclopedia