#undef : Undefine Macro (Preprocessor Directive in C Programming)



#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 :

  1. TEMP is macro name is defined with value 10.
  2. TEMP is undefined and re-defined with new value as 75.
  3. Since macro constant TEMP has already defined.
  4. #ifdef condition is true.
  5. Directive #undef will undefined the macro constant TEMP but #define will again define symbol TEMP.