#undef : Undefine Macro (Preprocessor Directive in C Programming)
Contents
#undef : Preprocessor Directive in C Programming
Syntax:
#undef <identifier>
#undef : Undefines a symbol
Undefines a symbol specified by <identifier> which was previously defined with a #define directive.
- #undef Directive is used to undefine any Macro Symbol.
- #undef can undefine only “User Defined” Macro’s.
- #undef cannot undefine “Global Macro Identifiers“.
- #undef is used where we have to redefine any Macro Identifier.
#include<stdio.h> #define TEMP 10 #ifdef TEMP #undef TEMP #define TEMP 75 #else #define TEMP 100 #endif int main() { printf("%d",TEMP); return 0; }
Output :
75
Explanation :
- TEMP is macro name is defined with value 10.
- TEMP is undefined and re-defined with new value as 75.
- Since macro constant TEMP has already defined.
- #ifdef condition is true.
- Directive #undef will undefined the macro constant TEMP but #define will again define symbol TEMP.