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
How do we print only part of a string in c?
What are the different types of pointers used in c language?
Explain how can a program be made to print the line number where an error occurs?
What does %d do?
Can you think of a logic behind the game minesweeper.
Tell us two differences between new () and malloc ()?
Why c is a mother language?
What is the most efficient way to count the number of bits which are set in an integer?
Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop
what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above
What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25
What are linker error?
Which is the memory area not included in C program? give the reason
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
What is malloc() function?