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.
- Difference between getc(), getchar(), getch() and getche()
- What is the difference between printf, sprintf and fprintf?
- Bitwise Operators in C/C++
- C | Input and Output | Question 13
- Sequence Points in C | Set 1
- Scansets in C
- puts() vs printf() for printing a string
- How to Count Variable Numbers of Arguments in C?
- What is use of %n in printf() ?
- gets() is risky to use!
- Storage for Strings in C
- What is return type of getchar(), fgetc() and getc() ?
- Return values of printf() and scanf() in C/C++
- How to declare a pointer to a function?
- Write a C macro PRINT(x) which prints x