R
Robert Rotstein
Following is a C program, taken from
http://en.wikipedia.org/wiki/Quine#Sample_quine_in_C,
which has the curious property that, when executed, it produces its own
source code as output.
#include <stdio.h>
char x[]="#include <stdio.h>%cchar x[]=%c%s%c;%cint main()
{printf(x,10,34,x,34,10,10);return 0;}%c";
int main() {printf(x,10,34,x,34,10,10);return 0;}
But I can't figure it out! Specifically, I don't know the significance of
the hard-coded integers, nor how the % formatting characters work in this
instance. Can someone explain just how this works?
http://en.wikipedia.org/wiki/Quine#Sample_quine_in_C,
which has the curious property that, when executed, it produces its own
source code as output.
#include <stdio.h>
char x[]="#include <stdio.h>%cchar x[]=%c%s%c;%cint main()
{printf(x,10,34,x,34,10,10);return 0;}%c";
int main() {printf(x,10,34,x,34,10,10);return 0;}
But I can't figure it out! Specifically, I don't know the significance of
the hard-coded integers, nor how the % formatting characters work in this
instance. Can someone explain just how this works?