C Programming - C Preprocessor - Discussion

13. 

What will be the output of the program?

#include<stdio.h>
#define MESS junk

int main()
{
    printf("MESS\n");
    return 0;
}

[A]. junk
[B]. MESS
[C]. Error
[D]. Nothing will print

Answer: Option B

Explanation:

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


Punit Lohia said: (Aug 27, 2011)  
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: (Oct 2, 2011)  
Anything within quotes is treated as a statement. So it will not be treated as a MACRO.

Abirami Kesavaraman said: (Aug 13, 2013)  
Then how to print junk using MESS in printf?

Avi said: (Mar 18, 2015)  
/*One of the possibilities*/
/******************/

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

int main()
{
MESS;
return 0;
}

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.