Detailed explanation of printf usage

藏色散人
Release: 2020-03-03 09:39:10
Original
14947 people have browsed it

Detailed explanation of printf usage

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 ("", ). printf() is a C language standard library function, defined in stdio.h. In addition to letters, numbers, spaces, and some numeric symbols, the output string can also use some escape characters to express special meanings.

Recommended: "C Language Tutorial"

printf function definition

Function declaration

int printf(char *format...);
Copy after login

call Format

printf("<格式化字符串>", <参量表>);
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template