#ifdef statement : Conditional Compilation Directives (C Preprocessor)
What it does ?
- These Conditional Compilation Directives allow us to include certain portion of the code depending upon the output of constant expression
- Block is Called as Conditional Group
#ifdef MACRONAME
Statement_block;
#endif
Explanation :
- If the MACRONAME specified after #ifdef is defined previously in #define then statement_block is followed otherwise it is skipped
- We say that the conditional succeeds if MACRO is defined, fails if it is not.
#include"stdio.h"
#define NUM 10
void main()
{
#ifdef NUM
#define MAX 20 // Define another macro if MACRO NUM is defined
#endif
printf("MAX number is : %d",MAX);
}
Output :MAX Number is 20
Live Example 2 :
#include"stdio.h"
void main()
{
#ifdef MAX #define MIN 90
#else
#define MIN 100
#endif
printf("MIN number : %d",MIN);
}
Output :MIN number : 100
Rules :
- The MACRONAME inside of a conditional can include preprocessing directives.
- They are executed only if the conditional succeeds.
- You can nest conditional groups inside other conditional groups, but they must be completely nested.
- You cannot start a conditional group in one file and end it in another.

0 Comments:
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email