How do you write a program which produces its own source
code as its output?
Answer Posted / abhishek
#include <stdio.h>
static char prog[] = "#include <stdio.h>%c%cstatic char prog[] = %c%s%c;%c%cint main(void)%c{%c printf(prog, 10, 10, 34, prog, 34, 10, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c";
int main(void)
{
printf(prog, 10, 10, 34, prog, 34, 10, 10, 10, 10, 10, 10, 10);
return 0;
}
Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
What is a function in c?
int i=10; printf("%d %d %d", i, i=20, i);
What is the symbol indicated the c-preprocessor?
Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me
Can a function argument have default value?
can anyone please tell about the nested interrupts?
How can I find out the size of a file, prior to reading it in?
What is the size of structure in c?
what is the difference between 123 and 0123 in c?
If you know then define #pragma?
Do pointers need to be initialized?
Want to know how to write a C program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
What will the code below print when it is executed? int x = 3, y = 4; if (x = 4) y = 5; else y = 2; printf ("x=%d, y=%d ",x,y);
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
What is %s and %d in c?