Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

C | Macro & Preprocessor | Question 2

  • Last Updated : 02 Feb, 2013

Take a step-up from those "Hello World" programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.

#include <stdio.h>
#if X == 3
    #define Y 3
    #define Y 5
int main()
    printf("%d", Y);
    return 0;

What is the output of the above program?
(A) 3
(B) 5
(C) 3 or 5 depending on value of X
(D) Compile time error

Answer: (B)

Explanation: In the first look, the output seems to be compile-time error because macro X has not been defined. In C, if a macro is not defined, the pre-processor assigns 0 to it by default. Hence, the control goes to the conditional else part and 5 is printed. See the next question for better understanding.

My Personal Notes arrow_drop_up
Recommended Articles
Page :