Write a program that can print itself

Or to be more specific, write a program that can print itself, and by itself I mean, it's own source code, and it should ONLY do that. Nothing else.

This means, when you type the program out, compile, then run it, it should print exactly the program you typed in the first place, also, NO it can't read it's own source file, that's considered cheating. The program must be independent.

Wait... don't scroll yet. Think about it...



I bet you just scrolled anyway. If you thought about it however, just even for a few minutes you'd realize that this is a serious problem, and it might turn into an infinitely large program.

But programmers are usually smart people (well, some of them) and without further ado, here is a C program that prints itself.


That's it! and I don't mean to plagiarize, I got it from here: http://stackoverflow.com/questions/8596236/self-reproducing-program (The answer on this post explains the whole thing, read it!)

This sort of program is called a Quine : http://en.wikipedia.org/wiki/Quine_%28computing%29

Another pretty interesting page about Quines is this one and it includes an English Quine. Yes an English language "program" or instructions of sorts, that if followed, produces itself. :  http://c2.com/cgi/wiki?QuineProgram

Turns out you can learn something new everyday!