×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

C language #if, #elif, #else, #endif Pre-processor with Example

#if, #elif, #else, #endif

The pre-processor directives #if, #elif, #else, #endif are used as conditional compilation, whenever we need to compile specify code segments, we use these pre-processor directives.

Let's consider the following example

#include <stdio.h>

#define ENG_US	1
#define ENG_UK	2
#define FRENCH	3

#define LANGUAGE ENG_UK

int main(){
	
	#if LANGUAGE==ENG_US
		printf("Selected language is: ENG_US\n");
	#elif LANGUAGE==ENG_UK
		printf("Selected language is: ENG_UK\n");
	#else 
		printf("Selected language is: FRENCH\n");
	#endif
	
	return 0;
}

Output

Selected language is: ENG_UK



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.