A quine, in computing, is a program producing its complete source code as its only output without simply opening the source file of the program and printing the contents (such actions are considered cheating).

This type of program is offered as a somewhat more interesting alternative to HelloWorld programs.

Quines are named after the logician .

The name "quine" is coined by Douglas Hofstadter in his popular science book Gödel, Escher, Bach: An Eternal Golden Braid in the honor of philosopher Willard Van Orman Quine (1908–2000), who made an extensive study of indirect self-reference, and in particular for the following paradox-producing expression, known as Quine's paradox:

"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.

A quine is a fixed point of an execution environment, when the execution environment is viewed as a function. Quines are possible in any programming language that has the ability to output any computable string, as a direct consequence of Kleene's recursion theorem. For amusement, programmers sometimes attempt to develop the shortest possible quine in any given programming language.

The name has become popular between amateur enthusiasts and programming hobbyists although it is not adopted by computer scientists.

A quine takes no input. Allowing input would permit the source code to be fed to the program via the keyboard, opening the source file of the program, and similar mechanisms.

In some languages, an empty source file is a fixed point of the language, producing no output. Such a program can be considered the smallest quine in the world.

 

Here is a simple quine written in C language:

#include <stdio.h>

char x[]="#include <stdio.h>%cchar x[]=%c%s%c;%cint main() {printf(x,10,34,x,34,10,10);return 0;}%c";

int main() {printf(x,10,34,x,34,10,10);return 0;}

 

Gg1.