The #define directive substitutes expression for all further found entries of identifier in the source text. The identifier is replaced only if it is a separate token. The identifier is not replaced if it is part of a comment, part of a string, or part of another longer identifier.

The constant identifier is governed by the same rules as variable names. The value can be of any type:

Be sure to enclose parameters in parentheses when using the parameters in expression, as this will help avoid non-obvious errors that are hard to find. If we rewrite the code without using the brackets, the result will be different:

The #undef directive

#define MACROvoid func1() {#ifdef MACROPrint("MACRO is defined in ",__FUNCTION__); #elsePrint("MACRO is not defined in ",__FUNCTION__);#endif }#undef MACROvoid func2() {#ifdef MACROPrint("MACRO is defined in ",__FUNCTION__);#elsePrint("MACRO is not defined in ",__FUNCTION__);#endif }voidOnStart() { func1(); func2(); }/* Result: MACRO is defined in func1 MACRO is not defined in func2*/