C Sharpif - C Programming Tutorial
C Course / Preprocessor / C Sharpif

C Sharpif

BLUF: Understanding C Sharpif 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 Sharpif

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

C #if

Example

#if expression

//code

#endif

Syntax with #else:

Example

#if expression

//if code

#else

//else code

#endif

Syntax with #elif and #else:

Example

#if expression

//if code

#elif expression

//elif code

#else

//else code

#endif

C #if example

Let's explore a basic illustration of utilizing the #if preprocessor directive.

Example

Example

#include <stdio.h>

#include <conio.h>

#define NUMBER 0

void main() {

#if (NUMBER==0)

printf("Value of Number is: %d",NUMBER);

#endif       

getch();

}

Output:

Output

Value of Number is: 0

Let's explore a different instance to gain a better grasp of the #if directive.

Example

Example

#include <stdio.h>  

#include <conio.h>  

#define NUMBER 1

void main() {

clrscr();

#if (NUMBER==0)

printf("1 Value of Number is: %d",NUMBER);

#endif



#if (NUMBER==1)

printf("2 Value of Number is: %d",NUMBER);

#endif

getch();

}

Output:

Output

2 Value of Number is: 1

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