This blog is under construction

Sunday 3 June 2012

#undef directive in C

#undef directive is used to undefine a macro that has been defined earlier using #define. It is used if any macro is not needed or if the macro needs to redefined.

Example:
     #undef SAMPLE

The above statement would remove the definition for the macro named SAMPLE.

#undef directive example in C

  #include <stdio.h>
  #define NUM 10

  int main() {
        int a = NUM;
        printf("Value of a: %d\n", a);
        #undef NUM   // undefining macro NUM
        #ifdef NUM
             printf("NUM macro defined\n");  // this part is ignored as NUM is undefined
        #else
             printf("Undefine macro NUM\n");
        #endif
        return 0;
  }

  Output:
  jp@jp-VirtualBox:~/cpgms/preprocessor$ ./a.out
  Value of a: 10
  Undefine macro NUM



2 comments:

  1. Very informative text refering to C. Maybe i'm wrong but as far as I know, and checked there, C is popular in OS as well as enablement systems, mainly based on Android. Pleasewrite more in futureabout IT releted stuff, it's quite easy for total dumbs like me, even if I would like to learn programing, its a kind of nighmare for me.

    ReplyDelete
  2. Dell Laptop Repair Center in Noida is no.1 service center which provides door to door services in or its nearby areas. We have expert, technicians who can repair your laptop at your home. . Call us: 9891868324

    ReplyDelete