Ever wondered how to write a C program that can print it’s own source code. Well, here is the source code of a C program that when executed will print it’s own source code. In other words, the output of this program is exactly same as it’s source code. Here’s the program:
#include<stdio.h>
char *program=”#include<stdio.h>%cchar *program=%c%s%c;%cvoid main()%c{%cprintf(program,10,34,program,34,10, 10,10,10);%c}”;
void main()
{
printf(program,10,34,program,34,10,10,10,10);
}





I am Srikanth Ramesh, a computer engineer from India.
11 Comments
Hitesh
December 14, 2008 at 12:31 PMSlim0123
December 31, 2008 at 1:32 PMJAIDEEP
January 14, 2009 at 11:26 AMLearning C
February 9, 2009 at 9:37 PMbiswajit das
February 20, 2009 at 4:00 PMJagadish Kumar
June 3, 2009 at 9:40 PMaparajit
November 8, 2009 at 5:34 PMsatish
July 6, 2011 at 9:38 PMraju
July 25, 2011 at 12:52 AMmangesh
July 25, 2011 at 12:53 AMSH@HID
March 7, 2012 at 12:19 PM