#undef in c

Explanation of #undef directives in c programming language by examples, questions and answers

Directive #undef is used to undefine any macro constants except global identifiers. It is useful when we want to redefined any macro constants. For example:

#include<stdio.h>
#define ABC 25
#ifdef ABC
#undef ABC
#define ABC 50
#else
#define ABC 100
#endif

int main(){
        printf("%d",ABC);
return 0;
}

Output: 50
Explanation: Since macro constant ABC has already defined. So #ifdef condition is true. Directive #undef will undefined the macro constant ABC but #define will again define.