💡🔥Advanced

Print Source Code of Program Itself

Quine program

A Quine is a program that prints its own source code. This is achieved by storing the code as a string and printing it twice.

Program Code (Quine)

print_source.c
C
1#include <stdio.h>
2
3int main() {
4 char *code = "#include <stdio.h>%c%cint main() {%c char *code = %c%s%c;%c printf(code, 10, 10, 10, 34, code, 34, 10, 10, 10);%c return 0;%c}%c";
5 printf(code, 10, 10, 10, 34, code, 34, 10, 10, 10);
6 return 0;
7}

How it works:
• The program stores its structure as a string
• %c is used for newlines (ASCII 10) and quotes (ASCII 34)
• %s prints the string itself
• When printf runs, it reconstructs the complete source code

Note: Quines are more of a programming puzzle than practical code. They demonstrate interesting properties of self-reference in programming.

Want to Learn More?

Explore our comprehensive tutorials for in-depth explanations of C programming concepts.

Browse Tutorials
Back to All Examples