Asked by Tanuj
Here is the standard prototype of printf function in C.
int printf(const char *format, ...);
The format string is composed of zero or more directives: ordinary characters (not %), which are copied unchanged to the output stream; and conversion specifications, each of argument (and it is an error if insufficiently many arguments are given).
The character % is followed by one of the following characters.
The flag character
The field width
The length modifier
The conversion specifier:
See http://swoolley.org/man.cgi/3/printf for details of all the above characters. The main thing to note in the standard is the below line about conversion specifier.
A `%' is written. No argument is converted. The complete conversion specification is`%%'.
So we can print “%” using “%%”
We can also print “%” using below.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Nested printf (printf inside printf) in C
- What is use of %n in printf() ?
- Use of & in scanf() but not in printf()
- Cin-Cout vs Scanf-Printf
- Passing NULL to printf in C
- Execution of printf with ++ operators
- What is the difference between printf, sprintf and fprintf?
- puts() vs printf() for printing a string
- Return values of printf() and scanf() in C/C++
- How to change the output of printf() in main() ?
- How to print a variable name in C?
- Print Hello World without semicolon in C/C++
- How to Read and Print an Integer value in C
- How will you print numbers from 1 to 100 without using loop? | Set-2
- Print calendar for a given year in C++
- Print 1 2 3 infinitely using threads in C
- Print a long int in C using putchar() only
- Print 1 to 100 in C++, without loop and recursion
- Program to print last 10 lines
- Print "Even" or "Odd" without using conditional statement