Example 1
CODE
#include <conio.h>
#include <stdio.h>
#define NUM 0
void main() {
#if (NUM==0)
printf("Value of Num is : %d",NUM);
#endif
getch();
}
OUTPUT
Value of Num is : 0
Example 2
CODE
#include <stdio.h>
#define LEARNING 1
int main()
{
printf("Coding Ninjas Studio is a great ");
#if LEARNING
printf("learning ");
#endif
printf("platform.\n");
return 0;
}
OUTPUT
Coding Ninjas Studio is a great learning platform.
You can also read about dynamic array in c and Short int in C Programming
Frequently Asked Questions
What is the #if directive?
The #if is a preprocessor directive that allows for conditional compilation in the C programming language. The #if preprocessor directive basically evaluates the condition or the expression.
What does the preprocessor evaluate?
The preprocessor evaluates the expression given with if directive to check if the subsequent code will be included in the compilation process or not.
How does the #if directive is closed?
The #if directive must always be closed be with an #endif directive.
Conclusion
In this article, we have extensively about the C #if directive. We hope that this blog has helped you enhance your knowledge regarding #if directive in C language, and if you want to learn more, check out our articles here. Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But suppose you have just started your learning process and are looking for questions from tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problems, interview experiences, and interview bundle for placement preparations.
Nevertheless, you may consider our paid courses to give your career an edge over others!
Do upvote our blog to help other ninjas grow. Happy Coding!