C Sharpifndef - C Programming Tutorial
C Course / Preprocessor / C Sharpifndef

C Sharpifndef

BLUF: Understanding C Sharpifndef is a foundational part of learning C programming. This tutorial explains the core principles and syntax needed to implement this concept effectively.
Core Programming Principle: C Sharpifndef

C provides direct access to memory and system resources. Learn how C Sharpifndef leverages this power in the lesson below.

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

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience