Table of Contents
show
Conditional compilation means that a part of a program is compiled only if a certain condition comes out to be true
#if – #endif
Syntax
#if constant_exp
statements-set
#endif
#if – #else – #endif
Syntax
#if constant_exp
statements-set1
#else
statements-set2
#endif
#if – #elif – #endif
Syntax
#if constant_exp1
statement-set1
#elif constant_exp2
statement-set 2
#endif
#ifdef – #else – #endif
Syntax
#ifdef identifier
statement-set1
#elif constant-exp
statement-set2
#endif
#ifndef – #endif
Syntax
#ifndef identifier
statement-set1
#endif
#ifdef – #else – #endif
Syntax
#ifdef identifier
statement-set1
#elif constant-exp
statement-set2
#endif
#ifndef – #elif – #endif
Syntax
#ifndef identifier
statements-set1
#elif constant-exp
statements-set2
#endif
#ifndef – #else – #endif
Syntax
#ifndef identifier
statement –set1
#else
statement-set2
#endif
Example
#include <stdio.h>
#define x 10
int main()
{
#ifdef x
printf("hello\n"); // this is compiled as x is defined
#else
printf("bye\n"); // this isn't compiled
#endif
return 0;
}
Output
hello
Views: 0