Detailed explanation of printf usage
The function of the printf command is to format the output function, which is generally used to output to the standard output device. Output information in a specified format. The calling format of the printf() function is: printf ("
Recommended: "C Language Tutorial"
printf function definition
Function declaration
int printf(char *format...);
call Format
printf("<格式化字符串>", <参量表>);
The format string contains three objects, namely:
(1) String constant;
(2) Format control string;
(3) Escape characters.
String constants are output as they are and serve as prompts in the display. Each output item is given in the output table column, and it is required that the format control string and each output item should correspond one-to-one in quantity and type. The format control string is a string starting with %, followed by various format control characters to describe the type, width, precision, etc. of the output data. [
Format control string format
format-- is a string containing the text to be written to the standard output stdout. It can contain an embedded format tag, which can be replaced by the value specified in subsequent additional parameters and formatted as required.
The format control string format of printf is composed as follows:
%[flags][width][.prec][length]type
That is: %[flag][minimum width][.precision][type length] type
More For programming-related content, please pay attention to the Introduction to Programming column on the php Chinese website!
The above is the detailed content of Detailed explanation of printf usage. For more information, please follow other related articles on the PHP Chinese website!