C Programming - C Preprocessor - Discussion

Discussion Forum : C Preprocessor - Find Output of Program (Q.No. 13)
13.
What will be the output of the program?
#include<stdio.h>
#define MESS junk

int main()
{
    printf("MESS\n");
    return 0;
}
junk
MESS
Error
Nothing will print
Answer: Option
Explanation:

printf("MESS\n"); It prints the text "MESS". There is no macro calling inside the printf statement occured.

Discussion:
4 comments Page 1 of 1.

Punit lohia said:   1 decade ago
We have declared a macro template here, so it should replace the "mess" with junk? then why answer went wrong? please explain in detail.

Kamal said:   1 decade ago
Anything within quotes is treated as a statement. So it will not be treated as a MACRO.

Abirami kesavaraman said:   1 decade ago
Then how to print junk using MESS in printf?

Avi said:   1 decade ago
/*One of the possibilities*/
/******************/

#include<stdio.h>
#define MESS printf("junk\n")

int main()
{
MESS;
return 0;
}

Post your comments here:

Your comments will be displayed after verification.