The arrangement string is made out of nothing or more orders: customary characters (not %), which are duplicated unaltered to the result stream; and transformation details, every one of contention (and it is a blunder assuming deficiently numerous contentions are given).
Table of Contents
How to print % using printf()
The person % is trailed by one of the accompanying characters.
- The banner person
- The field widthThe accuracy
- The length modifier
- The change specifier:
See http://swoolley.org/man.cgi/3/printf for subtleties of all the above characters. The most compelling thing to note in the standard is the underneath line about change specifier.
For the most part, printf() work is utilized to print the text alongside the qualities. To print % as a string or text, you should utilize ‘%%’. Neither single % will print anything nor it will show any mistake or cautioning.
Example
#include<stdio.h> int main() { printf("%"); printf("%%"); getchar(); return 0; }
Output
%
There are some other ways to print % in the text message as in the following example,
Example
#include<stdio.h> #include<string.h> int main() { printf("welcome%\n"); printf("%%\n"); printf("%c\n",'%'); printf("%s\n","%"); char a[5]; strcpy(a, "%%"); printf("This is a's value: %s\n", a); return 0; }
Output
welcome% % 37 % % This is a's value: %%
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" , "%" ); |