What is the #elif directive in C?

A directive specifies how a compiler should process the input. The elif preprocessor directive in C is equivalent to an else if statement – it provides an alternate path of action when used with #if, #ifdef, or #ifndef directives.
Execution enters the #elif block when the #if condition is false and the elif condition holds true (this is shown below).

Syntax

#elif conditional_expression

The #elif directive must be succeeded by the #endif directive.

Code

#include <stdio.h>
#define checker 5
int main()
{
#if checker <= 3
printf("This is the if directive block.\n");
#elif checker > 3
printf("This is the elif directive block.\n");
#endif
return 0;
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved