C / C ++程序,它打印自己的源$ C $ C作为其输出 [英] C/C++ program that prints its own source code as its output
本文介绍了C / C ++程序,它打印自己的源$ C $ C作为其输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
维基百科说,它之所以被称为奎因,有人给了code如下:
Wikipedia says it's called a quine and someone gave the code below:
char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";main(){printf(s,34,s,34);}
但是,很明显你要添加
But, obviously you have to add
#include <stdio.h> //corrected from #include <stdlib.h>
,使的printf()
可以工作。
从字面上看,因为上面的程序没有打印的#include&LT;&stdio.h中GT;(?)
,这是没办法了。
Literally, since the above program did not print #include <stdio.h>
, it is not a solution (?)
我感到困惑的打印其自己的源$ C $ C,而这种问题的任何目的,字面要求尤其是在面试。
I am confused about the literal requirement of "print its own source code", and any purpose of this kind of problems, especially at interviews.
推荐答案
这里的窍门是,大多数编译器编译,而不需要包括 stdio.h中
。
The trick here is that most compilers will compile without requiring you to include stdio.h
.
他们通常只是抛出一个警告。
They will usually just throw a warning.
这篇关于C / C ++程序,它打印自己的源$ C $ C作为其输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文