C output question

后端 未结 2 618
旧巷少年郎
旧巷少年郎 2021-01-29 07:23

Why its output is %%??

#include
int main(void)
{
        printf(\"% % %\\n\");
return 0;
}
相关标签:
2条回答
  • It's undefined behaviour and absolutely anything can happen. Section 7.19.6.1/9 of C99 states:

    If a conversion specification is invalid, the behavior is undefined.

    and none of the preceding sections allow a conversion specifier of a space. They are limited to characters from the set diouxXfFeEgGaAcsPn%.

    0 讨论(0)
  • 2021-01-29 08:13

    If you use one %, it sees it as string (because it lacks other specifiers) and output %. If you use %%, it is to print % in output. if you use %%% the first two will be considered as outputting % and the last one as single "character". so you only get two %.

    0 讨论(0)
提交回复
热议问题