Quantcast
Channel: C/C++ program that prints its own source code as its output - Stack Overflow
Viewing all articles
Browse latest Browse all 11

C/C++ program that prints its own source code as its output

$
0
0

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>

so that the printf() could work.

Literally, since the above program did not print #include <stdio.h>, it is not a solution (?)

I am confused about the literal requirement of "print its own source code", and any purpose of this kind of problems, especially at interviews.


Viewing all articles
Browse latest Browse all 11

Latest Images

Trending Articles





Latest Images