printf(% d % f);
%d means that the output and input format is an integer, which is used for int int, short int;; %f means to output real numbers in decimal form, with 6 decimal places reserved by default.

In c language, the format of input and output is: input and output symbols (",< parameter table >), and the formatted string consists of two parts: format control and output table column, in which format control includes format declaration and ordinary characters.

The format declaration consists of "%"and format characters, such as %d, %f, etc. Its function is to convert the output data type into the specified format and then output it.

Extended data

The use of format characters in c language;

Inner diameter format symbol

Output 1 and% d according to the actual length of the integer.

2.% MD, where m is the width of the specified output field. If the number of data bits is less than meters, the left end is filled with spaces; If it is greater than meters, it will be output according to the actual number of digits. (3),% ld, output long integer data. Example: length a =135790; Printf ("%ld ",a), a total of; If you use% d output, an error will occur because the range of integer data is -32768 to 32767. For long integer data, it should be output in the format of% ld. For long integer data, you can also specify the field width, such as% %8LD.

2.o format characters, output integers in the form of octal numbers. Because the value of each bit in the memory cell (0 or 1) is output in octal form, the output value is unsigned, that is, the sign bit is also output as a part of octal.

3.x format symbol, output integer in the form of hexadecimal number. There will be no negative hexadecimal number. You can also use% lx to output long integers, or specify the output field width.

4. The symbols in U format are used to output unsigned data, that is, unsigned numbers, which are output in decimal form. Signed integers (int type) can also be output in% u format, and conversely, unsigned data can also be output in% d format. According to the rule of mutual assignment, unsigned data can also be output in %× format.

5.c format characters, used to output a character. Character data can also be output in integer form.

Six, S format characters, used to output a string.

1, printf of %s ("%s", "HELLO").

2. The output string of 2.% ms occupies the instrument column. If the string itself is larger than meters, the limit of meters will be broken and all strings will be output. If it is less than meters, the space on the left will be filled (3),%-. Millisecond If the string is less than meters, the left and right sides of the string are filled with spaces within meters.

3.% %m.ns, output the meter column, but only take the left end of the string? Characters. This? The character output is on the right side of the instrument column, leaving spaces on the left side.

4.%-m.ns, where m and n have the same meaning, output n characters on the left side of the meter range, and fill in the space on the right side if n >; M, the value is automatically taken, that is, guarantee? Characters are output normally.

Baidu Encyclopedia-Format Characters