I have tried escaping it using a backslash.
#include <stdio.h>
int main(void) {
printf("\%");
return 1;
}
But it doesn't work. What is the correct syntax?
I have tried escaping it using a backslash.
#include <stdio.h>
int main(void) {
printf("\%");
return 1;
}
But it doesn't work. What is the correct syntax?
printf("%%");
printf("\%");
will print % if you compile it in C89 mode (in K&R C, it is behavior defined).
In C99/11 this is not valid.
The double-quote
"and question-mark?are representable either by themselves or by the escape sequences\"and\?, respectively, but the single-quote'and the backslash\shall be represented, respectively, by the escape sequences\'and\\.
confirms that there is no escape sequence like \%.
The preferred way is
printf("%%");
Almost similar question is answered here .