C Programming - C Preprocessor - Discussion


What will be the output of the program?

#define MESS junk

int main()
    return 0;

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

Answer: Option B


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

#define MESS printf("junk\n")

int main()
return 0;

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.