ADVERTISEMENT
ADVERTISEMENT

The #if directive Example in C | C preprocessor programs

The #if preprocessor directive example/program: Here, we will learn how the #if directive works in C programming language.
Submitted by IncludeHelp, on August 25, 2018

The #if is a preprocessor directive in C programming language and it is used for conditional compilation.

General for of the #if directive is:

    #if conditional_expression 
	    statements;
    #endif

If conditional_expression is true, the code written between #if and #endif i.e. the statements will be executed.

Example:

#include <stdio.h>

#define MAX_GF 100

int main(){
	
	printf("Hello\n");
	#if MAX_GF>=50
		printf("Wau, you may have more than 50 girlfriends\n");
		printf("Code for more than 50 GFs\n");
	#endif
	printf("Bye!\n");
	
	return 0;
}

Output

    Hello
    Wau, you may have more than 50 girlfriends
    Code for more than 50 GFs
    Bye!

C Preprocessors Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.