このサイトで自分自身を印刷するプログラム、つまりプログラムコードを印刷するプログラムに出くわしました。
プログラムコードは次のとおりです。
#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;
}
そして与えられた説明は次のとおりです:
ここでの2つの重要なトリックは、%s指定子が埋め込まれた文字列を使用して、印刷時に文字列がそれ自体を含むようにすることと、%c形式指定子を使用して、改行などの特殊文字を印刷できるようにすることです。出力文字列。
プログラムがどのように機能しているか理解できませんでした。説明が必要な行、それらがどのように機能し、何をしているのかについて説明しました。説明してください。