C - Preprocessors #Ifndef #Endif - ifndef



 ifndef

Learn C - C tutorial - Ifndef - C examples - C programs

C Preprocessors #ifndef #endif - ifndef - Definition and Usage

  • #ifndef exactly acts as reverse as #ifdef directive.
  • If particular macro is not defined, “If” clause statements are included in source file.
  • Otherwise, else clause statements are included in source file for compilation and execution.
  • #endif’ always matches the nearest ‘#ifdef’ (or ‘#ifndef’, or ‘#if’).
  • Also, we cannot start a conditional group in one file and end it in another.
  • The number of necessary #endif directives changes according to whether the elseif or #else directive is used.
C Preprocessors #ifndef #endif

C Syntax

 #ifndef identifier 

#endif

  • #endif’ always matches the nearest ‘#ifdef’ (or ‘#ifndef’, or ‘#if’).
  • Also, we cannot start a conditional group in one file and end it in another.
  • The number of necessary #endif directives changes according to whether the elseif or #else directive is used.

C Syntax

 #endif newline 

Sample - C Code

#include<stdio.h>
#define wikitechy 
void main()
{
    #ifndef  wikitechy
    printf( "Hello! welcome to wikitechy world\n" );
    #define wiki
}
#else
    printf( "www.wikitechy.com\n" );
#endif
} 

C Code - Explanation :

  1. In C programming #include<stdio.h> specifies a statement which tells the compiler to insert the contents of stdio at that particular place. A header file is a C file, that typically ends in ".h".In this example, #define wikitechy defines the constant name WIKITECHY.
  2. In this example, #ifndef wikitechy specifies the reverse of #ifdef directive.
  3. #define wiki specifies the directive, there by executing the #else statement.
  4. The command #else specifies the else statement and prints the statement www.wikitechy.com.
  5. In this example, #endif specifies the end of the program.

Sample Output - Programming Examples

  1. Here in this output the “www.wikitechy.com” is printed in the console window since the #else directive has been defined.

View More Quick Examples


Related Searches to C Preprocessors Ifndef Endif