相关疑难解决方法(0)

打印自己的程序,它是如何工作的?

我遇到了一个在这个网站上打印自己的程序,即打印程序代码.

程序代码是:

#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;
}
Run Code Online (Sandbox Code Playgroud)

并给出的解释是:

这里的两个关键技巧是使用带有嵌入式%s说明符的字符串,以允许字符串在打印时包含自身,并使用%c格式说明符允许打印出特殊字符,如换行符,否则无法嵌入到输出字符串.

我不明白该程序是如何工作的.我已经提到了我需要解释的线条,它们如何工作以及它们在做什么.请解释.

c quine

18
推荐指数
1
解决办法
2万
查看次数

标签 统计

c ×1

quine ×1