Skip to content
Related Articles

Related Articles

Improve Article

C | Macro & Preprocessor | Question 4

  • Difficulty Level : Medium
  • Last Updated : 04 Feb, 2013
Geek Week




#include <stdio.h>
#define X 3
#if !X
    printf("Geeks");
#else
    printf("Quiz");
   
#endif
int main()
{
        return 0;
}

(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;
}
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.
My Personal Notes arrow_drop_up
Recommended Articles
Page :