All for Joomla All for Webmasters

C #undef

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

Syntax:

  1. #undef token

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

  1. #include <stdio.h>
  2. #define PI 3.14
  3. #undef PI
  4. main() {
  5.    printf(“%f”,PI);
  6. }

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.

  1. #include <stdio.h>
  2. #define number 15
  3. int square=number*number;
  4. #undef number
  5. main() {
  6.    printf(“%d”,square);
  7. }

Output:

225
PinIt
submit to reddit

Leave a Reply

Top