The printf () function outputs a formatted string.
Grammar
printf (format,arg1,arg2,arg++) parameter description
Format required. Specifies the string and how to format the variable.
Arg1 required. Specifies the parameter that is inserted into the first% symbol in a formatted string.
Arg2 is optional. Specifies the parameter that is inserted into the second% symbol in the formatted string.
arg++ is optional. Specifies the parameters that are inserted into the formatted string, such as the third to fourth, etc.% symbol.
Description
Arg1, arg2, + + etc parameters will be inserted into the main string percent percent (%) Symbol. This function is executed step-by. In the first% symbol, insert arg1, insert arg2 at the second% symbol, and so on.
Hints and Notes
Note: If the% symbol is more than the arg parameter, you must use a placeholder. The placeholder is inserted after the% symbol and consists of a number and a "$". See Example 3
The full format of printf format control:
%-0 M.N L or H format characters
The following describes the items that comprise the format description:
①%: Represents the starting symbol for the format description, which is indispensable.
②-: Yes-Indicates left-aligned output, such as omitting to indicate right-aligned output.
③0:0 indicates that the specified vacancy is filled in 0, as omitted to indicate that the specified space is not filled.
④m.n:m refers to the width of the field, which is the number of characters that the corresponding output item occupies on the output device. n refers to precision. The number of decimal digits used to describe the actual number of outputs. When n is specified, the implied precision is n=6 bit.
⑤l or h:l refers to the integer type long, which refers to the double type of the real type. H is used to Fu Xiu the format character of an integral type to a short type.
---------------------------------------
Format characters
The format character is used to specify the data type and output format of the output item.
①d format: Used to output decimal integers. There are several ways to use this:
%d: Output based on the actual length of the integer data.
%md:m the width of the specified output field. If the number of bits in the data is less than M, then the left is a space, and if it is greater than M, the actual number of digits is output.
%LD: Outputs long-integer data.
②o format: outputs integers in unsigned octal form. The long integer type can be output in the format "%lo". You can also specify the field width to be output in "%MO" format.
Cases:
Main ()
{int a =-1;
printf ("%d,%o", A, a);
}
Run Result: -1,177777
Program parsing:-1 in the memory unit (stored in complement form) is (1111111111111111) 2, converted to octal number is (177777) 8.
③X format: outputs integers in unsigned hexadecimal form. The long integer type can be output in the format "%LX". You can also specify the field width to be output in "%MX" format.
④u format: outputs integers in unsigned decimal form. The long integer type can be output in the format "%lu". You can also specify the field width to be output in "%MU" format.
1 2
http://www.bkjia.com/PHPjc/445388.html www.bkjia.com true http://www.bkjia.com/PHPjc/445388.html techarticle the printf () function outputs a formatted string. The syntax printf (format,arg1,arg2,arg++) parameter describes the format required. Specifies the string and how to format the variable. Arg1 required. ...