/

How to Print the Percentage Character Using `printf()` in C

How to Print the Percentage Character Using printf() in C

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:

1
printf("%");

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

1
2
3
4
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:

1
printf("%%");

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

Tags: C programming, printf(), printing characters