Can we create a program that print out its source code what if we (or the program itself) compile than the new program would have the same exact functionality what the original program has? So somehow it would reproduce himself in perfect clones that can reproduce too.
The program shouldn't use any external files othervise it would be realy easy to implement: we just need to create a program that reads a file than writes it out, than copy and paste the source code to the external file.
My first attempt was to write a program that has a print function than copy-paste the source code to this print function, but this program can reproduce himeself for only once, and doesn't have the same functionality because the second program cant print out the source code.

  • 4
    This is known as a Quine
    – user40980
    Commented Apr 18, 2013 at 22:33
  • Reasons for downvotes are appreciated.
    – totymedli
    Commented Apr 18, 2013 at 22:38
  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask
    – gnat
    Commented Apr 18, 2013 at 22:47
  • @gnat I wrote what I tried in the last paragraph, I told why it isn't worked, also I started the question with my needs and what I am curious about.
    – totymedli
    Commented Apr 18, 2013 at 22:51
  • 1
    well, somehow, it doesn't feel like you invested serious effort into research. For example, "quine" (and Wikipedia article on it) was first thing that popped up in my web search for words I took from your question: "program that print out its source code". How come that you were unable to find the term and article on the thing you're asking about?
    – gnat
    Commented Apr 18, 2013 at 23:03

2 Answers 2


That's called a quine. It's a frequent subject of programming challenges.

This page lists a large number of quines written in various languages. You can look at how it's implemented in those examples to get the general idea of how to write your own.


Yes, as p.s.w.g said this is called a quine.

A quine is a computer program which takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the computability theory and computer science literature are self-replicating programs, self-reproducing programs, and self-copying programs.

From: http://en.wikipedia.org/wiki/Quine_%28computing%29

And, that can be achieved in any programming language that is turing-complete

see here for more info: https://stackoverflow.com/questions/2568020/is-it-possible-to-create-a-quine-in-every-turing-complete-language

Also, on a related note, here you can find examples of quines and other programming puzzles: https://codegolf.stackexchange.com/search?q=quine

  • would you mind explaining more on what it does and what it's good for? "Link-only answers" are not quite welcome at Stack Exchange
    – gnat
    Commented Apr 18, 2013 at 22:53
  • Ok, I edited my answer, do you mind removing the down vote?
    – jsedano
    Commented Apr 18, 2013 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.