write a program wch produces its own source code aas its
output?

Answer Posted / guest

#include <stdio.h>

int main(int argc, char** argv)
{
/* This macro B will expand to its argument, followed by a
printf
command that prints the macro invocation as a literal
string */
#define B(x) x; printf(" B(" #x ")\n");

/* This macro A will expand to a printf command that prints
the
macro invocation, followed by the macro argument itself. */
#define A(x) printf(" A(" #x ")\n"); x;

/* Now we call B on a command to print the text of the
program
up to this point. It will execute the command, and then
cause
itself to be printed. */
B(printf("#include <stdio.h>\n\nint main(int argc, char**
argv)\n{\n/*
This macro B will expand to its argument, followed by a
printf\n
command that prints the macro invocation as a literal
string
*/\n#define B(x) x; printf(\" B(\" #x \")\\n\");\n\n/*
This macro
A will expand to a printf command that prints the\n
macro invocation, followed by the macro argument itself.
*/\n#define A(x)
printf(\" A(\" #x \")\\n\"); x;\n\n/* Now we call B on
a command
to print the text of the program\n up to this point. It
will execute
the command, and then cause\n itself to be printed.
*/\n"))
A(printf("/* Lastly, we call A on a command to print the
remainder
of the program;\n it will cause itself to be printed,
and then
execute the command. */\n}\n"))
/* Lastly, we call A on a command to print the remainder of
the program;
it will cause itself to be printed, and then execute the
command. */
}

Is This Answer Correct ?    2 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I read the arrow keys? What about function keys?

618


what is the diffrenet bettwen HTTP and internet protocol

1396


Differentiate fundamental data types and derived data types in C.

621


Where are c variables stored in memory?

601


How can I dynamically allocate arrays?

601






Calculate 1*2*3*____*n using recursive function??

1522


What are the features of c language?

625


What does return 1 means in c?

591


Why can’t we compare structures?

818


Write a program to reverse a given number in c language?

623


Why do we use c for the speed of light?

610


Are there namespaces in c?

571


How can I direct output to the printer?

820


What is pragma c?

620


Explain Basic concepts of C language?

652