Escape Percent Sign in printf Method in C++

In this post, we will see how to escape percent sign in printf Method in C++.

Escape percent sign in Printf Method in C++

printf() method uses percent sign(%) as prefix of format specifier.
For example:
To use number in prinf() method, we use %d, but what if you actually want to use percent sign in the String.

Output

As you can see, it didn’t print output as expected.

If you want to escape percent sign in printf() method, you can use % twice (%%).

Here is an example:

Output

If you don’t require any formats in String, you can use puts or fputs as well.

Output

That’s all about how to escape percent sign in printf Method in C++.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *