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 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", "%"); |
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.
Recommended Posts:
- Nested printf (printf inside printf) in C
- Return values of printf() and scanf() in C/C++
- What is use of %n in printf() ?
- How to change the output of printf() in main() ?
- Passing NULL to printf in C
- Cin-Cout vs Scanf-Printf
- Execution of printf with ++ operators
- What is the difference between printf, sprintf and fprintf?
- Use of & in scanf() but not in printf()
- puts() vs printf() for printing a string
- How will you print numbers from 1 to 100 without using loop?
- Write a C program to print "Geeks for Geeks" without using a semicolon
- Print "Even" or "Odd" without using conditional statement
- Print a long int in C using putchar() only
- Print substring of a given string without using any string function and loop in C
- Print individual digits as words without using if or switch
- Print "Hello World" in C/C++ without using any header file
- C Program to print numbers from 1 to N without using semicolon?
- How to print a semicolon(;) without using semicolon in C/C++?
- Write a C program to print "GfG" repeatedly without using loop, recursion and any control structure?

