Home  >  Article  >  Backend Development  >  What does printf mean in c language?

What does printf mean in c language?

angryTom
angryTomOriginal
2020-02-29 13:18:4559036browse

What does printf mean in c language?

What does printf mean in C language

In C language, printf is a library function. It is declared in the header file stdio.h, and its function is to output a string according to the format specified by the user. When the system executes this function, it will output the ordinary characters in the string one by one as they are. If an escape character is encountered, the corresponding output will be based on its meaning (for example: after encountering \n, it will change to a new line, which is equivalent to the keyboard Press Enter). If a format character is encountered, the numerical type represented by the character is determined, and then an expression is retrieved from the subsequent output table column, its value is calculated, and the format character is replaced with the result.

Recommended learning: c language video tutorial

Function prototype:

void printf(const char *format,...);

When formatting output, format in the parameter Format flag.

%d The integer parameters will be converted into signed decimal numbers
%u The integer parameters will be converted into unsigned decimal numbers
%o The integer parameters will be converted into Convert to unsigned octal number
%x The integer parameter will be converted to unsigned hexadecimal number, and represented by lowercase abcdef
%X The integer parameter will be converted to unsigned hexadecimal number decimal number, and expressed in uppercase ABCDEF
%f Double type parameters will be converted into decimal numbers, and rounded to six digits below the decimal point
%e Double type parameters are printed in exponential form, with one The number will be before the decimal point, the six digits will be after the decimal point, and the exponent part will be represented by a lowercase e
%E has the same effect as %e, the only difference is that the exponent part will be represented by a capital E
%g Double type parameters will automatically choose to be printed in the format of %f or %e. The standard is determined based on the printed value and the number of significant digits set.
%G has the same effect as %g, the only difference is that when printing in exponential form, the %E format will be selected.
%c Integer parameters will be converted to unsigned char type and printed out
%s Parameters pointing to strings will be output verbatim until NULL characters appear
%p If the parameter is " The void *" type pointer is displayed in hexadecimal format

Example:

# include <stdio.h>
int main(void)
{
    int i = 10;
    printf("%d\n", i);  /*%d是输出控制符,d 表示十进制,后面的 i 是输出参数*/
    return 0;
}

PHP Chinese website, a large number of Introduction to Programming tutorials, welcome to learn!

The above is the detailed content of What does printf mean in c language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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