Programming in C: Unit I (d): Preprocessor Directives

#undef

with Example C Programs | Preprocessor Directives

As the name suggests, the #undef directive undefines or removes a macro name previously created with #define. Undefining a macro means to cancel its definition.

#UNDEF

As the name suggests, the #undef directive undefines or removes a macro name previously created with #define. Undefining a macro means to cancel its definition. This is done by writing #undef followed by the macro name that has to be undefined.

Like definition, undefinition also occurs at a specific point in the source file, and it applies starting from that point. Once a macro name is undefined, the name of the macro ceases to exist (from the point of undefinition) and the preprocessor directive behaves as if it had never been a macro name.

Therefore, the #undef directive removes the current definition of macro and all subsequent occurrences of macro name are ignored by the preprocessor.

Note

If you had earlier defined a macro with parameters, then when undefining that macro you do not have to give the parameter list. Simply specify the name of the macro.

You can also apply the #undef directive to a macro name that has not been previously defined. This can be done to ensure that the macro name is undefined.

The #undef directive when paired with a #define directive creates a region in a source program in which the macro has a special meaning. For example, a specific function of the source program can use certain constants to define environment-specific values that do not affect the rest of the program.

The #undef directive can also be paired with the #if directive to control conditional compilation of the source program. We will read about the #if directive later in this section.

Consider the following example in which the #undef directive removes definitions of a symbolic constant and a macro.

#define MAX 10

#define MIN (X, Y) (((X) < (Y)) ? ((X): (Y))

.

.

.

#undef MAX

#undef MIN

Programming in C: Unit I (d): Preprocessor Directives : Tag: : with Example C Programs | Preprocessor Directives - #undef


Programming in C: Unit I (d): Preprocessor Directives



Under Subject


Programming in C

CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation



Related Subjects


Professional English II

HS3251 2nd Semester 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation


Statistics and Numerical Methods

MA3251 2nd Semester 2021 Regulation M2 Engineering Mathematics 2 | 2nd Semester Common to all Dept 2021 Regulation


Engineering Graphics

GE3251 eg 2nd semester | 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation


Physics for Electrical Engineering

PH3202 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Basic Civil and Mechanical Engineering

BE3255 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Electric Circuit Analysis

EE3251 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Physics for Electronics Engineering

PH3254 - Physics II - 2nd Semester - ECE Department - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Electrical and Instrumentation Engineering

BE3254 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Circuit Analysis

EC3251 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Materials Science

PH3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation


Basic Electrical and Electronics Engineering

BE3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation


Physics for Civil Engineering

PH3201 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation


Basic Electrical, Electronics and Instrumentation Engineering

BE3252 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation


Physics for Information Science

PH3256 2nd Semester CSE Dept | 2021 Regulation | 2nd Semester CSE Dept 2021 Regulation


Basic Electrical and Electronics Engineering

BE3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation


Programming in C

CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation