There are, of course, several examples of self-printing C code.
The following is a very short self-printing (nonstandard) C program
(origin unknown):
main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}";printf(a,34,a,34);}
Assumptions:
- The program is run on an ASCII machine.
- No newline is needed at the end of the source.
- char * does not lose any information when converted to int.
- int has the same bit representation, size, and
argument passing convention as char *.
- A random return value from main does not cause problems.
- printf works without prototype.
Last update: 2000 December 10