在C中使用printf时如何转义%符号?

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

当前回答

你可以简单地使用两次%,即%%

例子:

printf("You gave me 12.3 %% of profit");

其他回答

您使用的格式说明符不正确。您应该使用%%来打印%。你的代码应该是:

printf("hello%%");  

阅读更多C语言中使用的格式说明符。

使用双%%:

printf("hello%%");

是这样的:

printf("hello%%");
//-----------^^ inside printf, use two percent signs together

双字符“%”也适用于“. format(…)”。 示例(iDrawApertureMask == 87, fCornerRadMask == 0.05): csCurrentLine.Format(“\ %添加% 2 d C %, % 6.4 f * \ %”,iDrawApertureMask, fCornerRadMask); 给出csCurrentLine中(字符串内容)的期望值和期望值; “% ADD87C, 0.0500 * %”

是的,使用printf("hello%%");做完了。