C Program to Print it’s Own Source Code

C Program to Print it's Own Source CodeEver 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);
}

11 Comments

  1. Hitesh
    December 14, 2008 at 12:31 PM

    Hey Srikanth, can u please send me such type of c programs @ [email protected].
    this is a great site which helped me a lot
    great work is done by u for learners of c Keep it up.


  2. Slim0123
    December 31, 2008 at 1:32 PM

    how about one more the smallest quine ever

    main() { char *s=”main() { char *s=%c%s%c; printf(s,34,s,34); }”; printf(s,34,s,34); }


  3. JAIDEEP
    January 14, 2009 at 11:26 AM

    hello Srikanth,
    can u please mail me some game source codes


  4. Learning C
    February 9, 2009 at 9:37 PM

    Can u please explain the code????


  5. biswajit das
    February 20, 2009 at 4:00 PM

    Hi
    srikanth please send me c code which is destroy the another exe files of windows


  6. Jagadish Kumar
    June 3, 2009 at 9:40 PM

    #include
    main()
    {
    FILE *fp=fopen(__FILE__,”r”);
    char ch;
    printf(“Hello World\n”);
    while(!feof(fp))
    {
    ch=fgetc(fp);
    printf(“%c”,ch);
    }
    }

    This program also prints it out source code as output .


  7. aparajit
    November 8, 2009 at 5:34 PM

    can we use this program to get source code of exe file that has been coded in c language ,please mail it to [email protected]

    with thanks.


  8. satish
    July 6, 2011 at 9:38 PM

    can it possible to run a .exe or .mp3 or .jpeg or etc… files through
    c or c++


  9. raju
    July 25, 2011 at 12:52 AM

    nice trick thanx


  10. mangesh
    July 25, 2011 at 12:53 AM

    thanx you sir


  11. SH@HID
    March 7, 2012 at 12:19 PM

    Sir,
    very nice programes
    very much useful for me
    Thaks for this


Leave A Reply