%% or \%
#include <stdio.h>int main(int argc, char *argv[])
{
printf("I want to print \%.\n");
printf("I want to print %%.\n");
return 0;
}
codeblocks(GCC)运行的结果是:
I want to print
I want to print %.
K&R在1.2节末提到,printf also recognizes %o for octal, ... and %% for itself.
C A Reference Manual第400页提到,Because a percent sign is used to indicate the beginning of a conversion specification, it is necessary to write two of them to have one printed. The complete conversion specification must be %%.
Standard C要求打印%必须用%%,但有些编译器要求不同,网上还有人说\%也可以打印%。
[ 本帖最后由 xiehou314159 于 2012-5-25 17:31 编辑 ]