C #ifndef
Example
#ifndef MACRO
//code
#endif
Syntax with #else:
Example
#ifndef MACRO
//successful code
#else
//else code
#endif
C #ifndef example
Let's explore a basic illustration demonstrating the utilization of the #ifndef preprocessor directive.
Example
Example
#include <stdio.h>
#include <conio.h>
#define INPUT
void main() {
int a=0;
#ifndef INPUT
a=2;
#else
printf("Enter a:");
scanf("%d", &a);
#endif
printf("Value of a: %d\n", a);
getch();
}
Output:
Output
Enter a:5
Value of a: 5
If you fail to specify an INPUT, the program will proceed to execute the code within the #ifndef block.
Example
Example
#include <stdio.h>
#include <conio.h>
void main() {
int a=0;
#ifndef INPUT
a=2;
#else
printf("Enter a:");
scanf("%d", &a);
#endif
printf("Value of a: %d\n", a);
getch();
}
Output:
Output
Value of a: 2