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


Please Help Members By Posting Answers For Below Questions

What does the error message "DGROUP exceeds 64K" mean?

992


Explain what is the stack?

842


What is a struct c#?

784


Is it valid to address one element beyond the end of an array?

926


I came across some code that puts a (void) cast before each call to printf. Why?

965


Is Exception handling possible in c language?

1801


number of times a digit is present in a number

1790


i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none

833


write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays

2002


Compare and contrast compilers from interpreters.

911


5 Write an Algorithm to find the maximum and minimum items in a set of ‘n’ element.

1839


Explain the difference between the local variable and global variable in c?

838


Explain how does flowchart help in writing a program?

874


List the variables are used for writing doubly linked list program.

1822


swap 2 numbers without using third variable?

876