Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is the #elif directive in C?

Sheza Munir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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;
}

RELATED TAGS

c

CONTRIBUTOR

Sheza Munir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring