March 29, 2010
A Quine in C
by Marco Vitanza

A Quine is a computer program which produces its own source code as the (only) output.

With the help of printf(), we can make a quine in 117 bytes of error- and warning-free C code (tested GCC 4.2).


However, with a little trickery, we can reduce it down to just 74 bytes. The compiler will complain, but we really don't need the #include (GCC links against the C library automatically). We can also save 2 bytes by replacing char with int. Who needs types, right? Bytes are bytes.


These are available as text files here: quine.c, and quine_nowarnings.c. If you want to try them yourself, make sure your text editor uses a single newline character (ASCII 10) for line endings.

$ gcc quine.c
$ ./a.out > tmp
$ diff tmp quine.c

Post Comment

Security Code: Verification Code Five Digits