Preprocessors: #if, #elif, #else, #endif
Applies To: C++Builder 1 or higher
Category: C++ Language
- The #if, #elif, #else and #endif are used to evaluate conditional statements. If the expression specified after #if is true, the compiler will execute the code between #if and #endif. You can also use #elif and #else to provide alternatives:
-
- char *s;
- #if 5 < 10
- s = "5 is less than 10";
- #else
- s = "5 is greater than or equal to 10";
- #endif
-
- #if can be used with the defined preprocessor operator to check if an identifier was already defined using #define. The following example checks if VALUE is defined and if yes, it undefines it:
-
- #define VALUE 100
-
- #if defined VALUE
- #undef VALUE
-
- // Compiler error
- int x = VALUE;
C++Builder Developer's Network
Copyright © Yoto Yotov