Printf() is the most widely used output function in C. We have used printf() for many printing operations previously. Let us know more about the printf() statement. In C, printf() has a certain format strings which define what should be output of the program.
We already know the prototype of the printf() function. If not, click here to know.
A printf() statement can take any number of arguments based on the need we have. But the total format strings of printf() are broadly classified into three types.
We already know the prototype of the printf() function. If not, click here to know.
A printf() statement can take any number of arguments based on the need we have. But the total format strings of printf() are broadly classified into three types.
- Literal Text
- Escape sequences
- Conversion specifier
A literal text is that which is constant and prints as it is, when a printf() statement is executed. It is the general string we have in printf().
The escape sequence is the characters we use for getting the output in newline or having some functions. You can know more about them, by clicking here.
The conversion specifier is the specifier that makes the output to be in a specific format. In C, we have a set of format specifiers based on the data type of the variables we take. Follow this link to get the list of format specifiers.
Example:
printf("The number is %d\n",a);In the above example,
- "The number is" is literal text.
- "\n" is the escape character.
- "%d" is the conversion specifier.
In scanf() function also we can find this format specifiers.
For using the printf() and scanf() function, we have to include STDIO.H package and a printf() statement must have a format String and the arguments based on the need. For each argument, there should be a format specifier.