Alex Rivera | Logout

How to escape the % (percent) sign in C's printf

Asked 2009-12-07T14:02:08.353
351

How do you escape the % sign when using printf in C?

printf("hello\%"); /* not like this */
Edit
Report

1 Answer

5

The backslash in C is used to escape characters in strings. Strings would not recognize % as a special character, and therefore no escape would be necessary. printf is another matter: use %% to print one %.

answered 2009-12-07T14:07:08.963

Your Answer