The Wayback Machine - https://web.archive.org/web/20211121194207/https://www.geeksforgeeks.org/how-to-print-using-printf/
Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

How to print % using printf()?

  • Difficulty Level : Easy
  • Last Updated : 28 May, 2017

Asked by Tanuj

Here is the standard prototype of printf function in C.

Take a step-up from those "Hello World" programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.
          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 precision
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 “%%”




/* Program to print %*/
#include<stdio.h>
/* Program to print %*/
int main()
{
   printf("%%");
   getchar();
   return 0;
}

We can also print “%” using below.




printf("%c", '%');
printf("%s", "%");
My Personal Notes arrow_drop_up
Recommended Articles
Page :