C #undef

The #undef preprocessor directive is used to undefine the constant or macro defined by #define.

Syntax:

snippet
#undef token

Let's see a simple example to define and undefine a constant.

snippet
#include 
#define PI 3.14
#undef PI
main() {
   printf("%f",PI);
}

Output:

Output
Compile Time Error: 'PI' undeclared

The #undef directive is used to define the preprocessor constant to a limited scope so that you can declare constant again.

Let's see an example where we are defining and undefining number variable. But before being undefined, it was used by square variable.

snippet
#include 
#define number 15
int square=number*number;
#undef number
main() {
   printf("%d",square);
}

Output:

Output
225
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents