What is the difference between #define and #undefine in c /c++?

define and # undef are compiler directives in C and C++.

The # define directive creates a definition for something that will be replaced multiple times in the code.

The # undef (undefine) counterpart removes the definition from what the compiler sees. It is usually specified when either the definition should no longer be used or when the definition needs to change.

The #define directive substitutes token-string for all subsequent occurrences of an identifier in the source file. The identifier is replaced only when it forms a token. (See C++ Tokens in the C++ Language Reference.) For instance, identifier is not replaced if it appears in a comment, within a string, or as part of a longer identifier.

The [b]#undef directive [/b]removes the current definition of identifier. Consequently, subsequent occurrences of identifier are ignored by the preprocessor. To remove a macro definition using #undef, give only the macro identifier ; do not give a parameter list.

You can also apply the #undef directive to an identifier that has no previous definition. This ensures that the identifier is undefined. Macro replacement is not performed within #undef statements.