Ever wondered how to write a C program to print its own source code? Well, here is the source code of a C program that when executed will print its own source code. In other words, the output of this program is exactly same as its 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); }
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); }
hello Srikanth,
can u please mail me some game source codes
Can u please explain the code????
Hi
srikanth please send me c code which is destroy the another exe files of windows
#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 .
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.
can it possible to run a .exe or .mp3 or .jpeg or etc… files through
c or c++
nice trick thanx
thanx you sir
Sir,
very nice programes
very much useful for me
Thaks for this
I am unable to understand this code(source code as output) please explain me.
Could you please tell me how to convert C program(source code) to software or application.
@ Raj
It is explained in my other post on: How to compile C programs?
what will be the output of followng c program:
1.main()
{
int i=10;
i=!i>14;
printf(“i=%d”,i);
}
and second program is
2.#define square(X)x*x
main()
{
int i;
i=64/square(4);
printf(“%d”,i);
}
if possible pls explain it for me…
thnks
The second one is possible !
The square(x)x (simply modified by the preprocessor) the x which is passed, For example if we pass the value of x as 4, it will be replaced by the preprocessor as 4, consider square(4)4*4:
square(4)4 replaced by 4 and multiplied by 4 so the value is 16
#include
#define square(x)x*x
int main()
{
int i;
i=64/(square(4));
printf(“%d”,i);
return 0;
}
In the above code snippet (Square(4)) will be replaced by 16 so 64 divided by 16 is 4
The Possible Output is 4.
HI, bro i’m a big fan of your site i had learnt so many thing from your blog
i just want to ask you something ….
1.You ever wondered to create page in your site which tutors the c language?
2.where can i found a complete tutorial to c language from A to Z?.
You can try: cprogramming.com
can u please explain me the code ….
hello sir
sir i Iike so much this article related to creating a virus which given by you.
please let me know how to create a virus to transfer any data. from D: directory to any portable USB
thank u
HELLO SIR
I AM ASHISH. I WANT TO RUN MY C PROGRAME EXE BEFORE WINDOW BOOT BUT I TRIED A LOT BUT I WAS FALIURE . WILL U TEEL ME THE PROCESS IF ITS POSSIBLE .