c ifndef
The directives #ifdef and #ifndef provide an alternative short form for the combining #if with defined operator.
let take examples of comparasions
#if defined(micro_name) is equivalent to #ifdef macro_name
syntax of #ifdef
if the macro_name has been defined with the directive #define , then statements are compile between #ifdef and #endif .If micro_name not be defined or undefined using #undef directive then these statements will not compiled
syntax of #ifndef
if macro_name has been defined using the #define and undefined using #undef, then these statements are not compiled, if the macro_name has not been defined using the #define and if we undefined using #undef , then the statements between #ifndef and #endif will compiled.
let us take example to understand
/* program to understand the use of #ifdef directive */
COUNT
main()
{
a=30,b=3;
COUNT
printf("COUNT is defined \n");
a++;
b--;
printf("a=%d,b=%d \n",a,b);
printf("program complete \n");
0;
}
|
output:
COUNT is defined
a=31,b=2
program complete
|
So in the above example FLAG has been defined, so the statements between directive #ifdef and directive #endif are compiled. if we delete the defination of marcro COUNT from the program, then these statements will not be compiled and the output of the program would be
output:
a=31,b=2
program complete
|
/* program to understand the use of #ifndef directive */
main()
{
a=18,b=3;
MAX
printf("MAX is not defined \n" );
a--;
b--;
printf("a=%d and b=%d\n", a,b);
printf("program complete \n" );
0;
}
|