C Programming - C Preprocessor - Discussion


Which of the following are correct preprocessor directives in C?
1: #ifdef
2: #if
3: #elif
4: #undef

[A]. 1, 2
[B]. 4
[C]. 1, 2, 4
[D]. 1, 2, 3, 4

Answer: Option D


The macros #ifdef #if #elif are called conditional macros.

The macro #undef undefine the previosly declared macro symbol.

Hence all the given statements are macro preprocessor directives.

Preeti said: (Sep 18, 2011)  
What is the use of #if ?

Nitesh said: (Dec 5, 2020)  

1.) As we use If Condition in our basic program like that in Macro we use #if #elif #endif.

2.) #undef = It used to undefine the define Macro.
Example. #define PI 3.14.
#undef PI // It will destroy PI so now there is no PI exists.
3.) #ifdef = Used to check Macro is Defined or Not.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.