我遇到了一个在这个站点上打印自己的程序,即它打印程序代码。
程序代码为:
#include <stdio.h>
char *program = "#include <stdio.h>%cchar *program = %c%s%c;%cint main()%c{%cprintf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c";
//what is this line doing, what is the use of %c and %s and what properties of %c and %s are being used here?
int main()
{
printf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);
//what is this print function doing, and how?
return 0;
}
给出的解释是:
这里的两个关键技巧是使用带有嵌入式 %s 说明符的字符串以允许字符串在打印时包含自身,以及使用 %c 格式说明符来允许打印出特殊字符,例如换行符,否则这些字符无法嵌入到输出字符串。
我不明白程序是如何工作的。我已经提到了我需要解释的行,它们是如何工作的以及它们在做什么。请解释。