Generally, printf() function is used to print the text along with the values. If you want to print % as a string or text, you will have to use ‘%%’. Neither single % will print anything nor it will show any error or warning.
Here is an example to print % in printf() in C language,
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: %%