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.
By IncludeHelp Last updated : March 10, 2024

C #if directive

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

Syntax

General syntax 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.

C #if directive 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 »


Comments and Discussions!

Load comments ↻






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