### Question 12.6

How can I print a `'%'` character in a `printf` format string? I tried `\%`, but it didn't work.

Simply double the percent sign: `%%` .

`\%` can't work, because the backslash `\` is the compiler's escape character, while here our problem is that the `%` is `printf`'s escape character.

See also question 19.17.

References: K&R1 Sec. 7.3 p. 147
K&R2 Sec. 7.2 p. 154
ANSI Sec. 4.9.6.1
ISO Sec. 7.9.6.1

Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995 // mail feedback