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
#elifdirective must be succeeded by the#endifdirective.
Code
#include <stdio.h>#define checker 5int main(){#if checker <= 3printf("This is the if directive block.\n");#elif checker > 3printf("This is the elif directive block.\n");#endifreturn 0;}
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved