#include <stdio.h> #define X 3 #if !X printf("Geeks"); #else printf("Quiz"); #endif int main() { return 0; } |
chevron_right
filter_none
(A) Geeks
(B) Quiz
(C) Compiler Error
(D) Runtime Error
Answer: (C)
Explanation: A program is converted to executable using following steps
1) Preprocessing
2) C code to object code conversion
3) Linking
The first step processes macros. So the code is converted to following after the preprocessing step.
printf("Quiz");
int main()
{
return 0;
}
The above code produces error because printf() is called outside main. The following program works fine and prints “Quiz”
#include
#define X 3
int main()
{
#if !X
printf("Geeks");
#else
printf("Quiz");
#endif
return 0;
}
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- C | Macro & Preprocessor | Question 1
- C | Macro & Preprocessor | Question 2
- C | Macro & Preprocessor | Question 14
- C | Macro & Preprocessor | Question 5
- C | Macro & Preprocessor | Question 6
- C | Macro & Preprocessor | Question 7
- C | Macro & Preprocessor | Question 8
- C | Macro & Preprocessor | Question 9
- C | Macro & Preprocessor | Question 10
- C | Macro & Preprocessor | Question 11
- C | Macro & Preprocessor | Question 12
- C | Macro & Preprocessor | Question 13
- C | Macro & Preprocessor | Question 14
- C | Macro & Preprocessor | Question 15
- Write a C macro PRINT(x) which prints x
- The OFFSETOF() macro
- CRASH() macro - interpretation
- How a Preprocessor works in C?
- C/C++ Preprocessor directives | Set 2
- C | Loops & Control Structure | Question 1

