Home » C programming language

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





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.