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



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

Answer / 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

More C Interview Questions

What Is The Difference Between Null And Void Pointer?

0 Answers   TCS,


get any number as input except 1 and the output will be 1.without using operators,expressions,array,structure.don't print 1 in printf statement

3 Answers  


What is auto keyword in c?

0 Answers  


Is double link list a linear data structure? If Yes, Why?If No, Why?

4 Answers  


What is a void pointer? When is a void pointer used?

0 Answers   Aspire, Infogain,






Where are c variables stored in memory?

0 Answers  


Is main is user defined function?

0 Answers  


1,1,5,17,61,217,?,?.

3 Answers   Apple,


How can I direct output to the printer?

0 Answers  


write a program for the normal snake games find in most of the mobiles.

0 Answers   Accenture, Wipro,


Q. where is the below variables stored ? - volatile, static, register

3 Answers   Bosch,


What compilation do?

7 Answers   Geometric Software, Infosys,


Categories