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.
- Flag character
- Field width
- Precision
- Length modifier
- Conversion specifier
Check this 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 “%%”
c
#include <stdio.h>
int main()
{
printf("%%");
getchar();
return 0;
}
|
We can also print “%” using below.
printf(“%c”, ‘%’);
printf(“%s”, “%”);
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!
Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!
Last Updated :
08 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...