我遇到了一個程序,它打印在this網站上,即它打印程序代碼。打印自己的程序,它是如何工作的?
程序代碼是:
#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格式說明符 允許打印出像換行符那樣的特殊字符 ,否則該字符串不能嵌入輸出 字符串中。
我不明白該程序是如何工作的。我已經提到了我需要的解釋,他們是如何工作的以及他們在做什麼。請解釋。
我已經看到了這個問的次數最近。這是一個家庭作業或程序員的挑戰嗎? –
沒有這樣的事,我只是碰到它。如果這是一個家庭作業,我會使用作業標籤。 – SpeedBirdNine
你的評論打破了奎因:)另外,縮進在奎因中是不正確的。 [這是我最近在C++中的quine](http://codepad.org/sKvDs2Et)@MichaelDorgan:是的,它是一個歷史根源的程序員的挑戰 – sehe