Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Program that prints out its source code.
#include <stdio.h>
int main(int argc, char*argv[]) {
char s = '\\';
char p = '\"';
char n = '\n';
char *c[7] = {"#include <stdio.h>","int main(int argc, char*argv[]) {"," printf(","%s%c%s%c char s = '%c%c';%c char p = '%c%c';%c char n = '%cn';%c char *c[7] = {%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c};%c%s%c%s%c%s%c%s%c%s%c",",c[0],n,c[1],n,s,s,n,s,p,n,s,n,p,c[0],p,p,c[1],p,p,c[2],p,p,c[3],p,p,c[4],p,p,c[5],p,p,c[6],p,n,c[2],p,c[3],p,c[4],n,c[5],n,c[6],n);"," return 0;","}"};
printf("%s%c%s%c char s = '%c%c';%c char p = '%c%c';%c char n = '%cn';%c char *c[7] = {%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c};%c%s%c%s%c%s%c%s%c%s%c",c[0],n,c[1],n,s,s,n,s,p,n,s,n,p,c[0],p,p,c[1],p,p,c[2],p,p,c[3],p,p,c[4],p,p,c[5],p,p,c[6],p,n,c[2],p,c[3],p,c[4],n,c[5],n,c[6],n);
return 0;
$ gcc correct-self-rep.c
$ ./a.out > correct-self-rep.c
$ gcc correct-self-rep.c
$ ./a.out > correct-self-rep.c

I could do this all day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.