Learn how to print the percentage character using printf() in C.

When writing a C program, you may come across a situation where you need to print the % percentage character using printf().

This can be particularly useful if you are working on a program that involves calculating percentages, which is quite common when you’re learning the language and creating small programs.

So, how do you go about printing the percentage character using printf() in C?

If you try to use it like this:

printf("%");

It will not work, and the compiler will give you a warning message:

hello.c:9:14: warning: incomplete format specifier [-Wformat]
printf("%");
        ^
1 warning generated.

As a result, the % character will not be printed.

To resolve this issue, you need to use %% instead, like this:

printf("%%");

By doing so, you will successfully print the percentage character using printf() in C.

Tags: C programming, printf(), printing characters