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.