A quine is a program that, when run, produces an exact copy of its original source code.
Here are two quines I made wrote in C—without cheating! They are both based on the same idea. The first one is macro‐based, utilizing the ability for macros to quote parameters.
Compiling and running it produces an exact copy of itself:
In the next quine I tried to do away with macros. First I tried quoting
program code, but then I had to quote quotation characters, and for each
compilation of the next quine, the quotation degraded quickly. The trick I
used was just to use
putchar instead. Not extremely elegant, but simple
Compiling and running the above program produces
Now, let's ponder the last example for a bit. You can see that I'm just writing out a bunch of numerical codes, with some boilerplate code to get it all started. In other words, we have some driver code and then a payload of specific data we print out. We can actually create a quine out of any program. That is the main point in Thompson's article.
This document is the HTML‐version of a gist I made earlier.