Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to print % using printf()?
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%
");
printf("%%
");
printf("%c
",'%');
printf("%s
","%");
char a[5];
strcpy(a, "%%");
printf("This is a's value: %s
", a);
return 0;
}
Output
welcome% % 37 % % This is a's value: %%
Advertisements
