C #else example
Here is a C program that shows how to use the #else directive in the C language:
#include <stdio.h>
#define AGE 20
int main()
{
#if AGE<18
printf("You are not an adult.\n");
#else
printf("You are an adult\n");
#endif
return 0;
}
You can also try this code with Online C Compiler
Run Code
Output
You are an adult
You can also read about dynamic array in c and Short int in C Programming
FAQs
What are # preprocessor operators In C?
The stringizing operator(#) converts the preceding input into a quoted string.
What is a macro in a C preprocessor?
A macro is a preprocessor directive that allows you to replace tokens in your source code. The #define statement is used to build macros.
Why is the #define directive used?
The #define directive specifies values or macros that the preprocessor will use to change the program source code before it is generated. Because preprocessor definitions are substituted before the compiler acts on the source code, any errors that are introduced by #define are challenging to trace.
What is __ LINE __ in C?
__LINE__ is a preprocessor macro that expands to the source file's current line number as an integer. When writing debugging code or generating log statements, __LINE__ comes in useful.
What are the types of C preprocessors?
There are mainly four types of preprocessor directives:
- Macros.
- File Inclusion.
- Conditional Compilation.
- Other directives.
Conclusion
In this article, we have extensively discussed the #else preprocessor directive.
We hope that this article has helped you enhance your knowledge regarding the #else preprocessor directive and if you would like to learn more, check out our article on Preprocessors in C.
Refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc.
Refer to the links problems, top 100 SQL problems, resources, and mock tests to enhance your knowledge.
For placement preparations, visit interview experiences and interview bundle.
Do upvote our blog to help other ninjas grow. Happy Coding!