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

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×