C | Macro & Preprocessor | Question 2
#include <stdio.h> #if X == 3 #define Y 3 #else #define Y 5 #endif int main() { printf("%d", Y); return 0; } |
chevron_right
filter_none
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.
Recommended Posts:
- C | Macro & Preprocessor | Question 5
- C | Macro & Preprocessor | Question 14
- C | Macro & Preprocessor | Question 4
- C | Macro & Preprocessor | Question 6
- C | Macro & Preprocessor | Question 13
- C | Macro & Preprocessor | Question 12
- C | Macro & Preprocessor | Question 7
- C | Macro & Preprocessor | Question 8
- C | Macro & Preprocessor | Question 14
- C | Macro & Preprocessor | Question 11
- C | Macro & Preprocessor | Question 15
- C | Macro & Preprocessor | Question 1
- C | Macro & Preprocessor | Question 10
- C | Macro & Preprocessor | Question 9
- The OFFSETOF() macro

