C Programming - C Preprocessor - Discussion

Discussion Forum : C Preprocessor - True / False Questions (Q.No. 2)
2.
Preprocessor directive #undef can be used only on a macro that has been #define earlier
True
False
Answer: Option
Explanation:

True, #undef can be used only on a macro that has been #define earlier

Example: #define PI 3.14

We can undefine PI macro by #undef PI

Discussion:
4 comments Page 1 of 1.

RafaelSorel said:   1 decade ago
Here is the use of #undef without the use of #define

{{{
#include "stdlib.h"
#undef EXECUTE_THIS_PART


void main(void)
{
#ifdef EXECUTE_THIS_PART
//do stuff here
#endif

retrun;
}

}}}

Susee said:   1 decade ago
Yes. Undef will work without define statement.

-susi.

Dmitri said:   1 decade ago
Not true at all. If the macro hasn't been defined, the #undef doesn't do anything, but it's still allowed. This lets you use #undef to make sure a macro is undefined, even where you don't know whether it has been defined or not.

Andras Joo said:   1 decade ago
Partially true.

//...
int PI;
#undef PI
//...

Works perfectly though without the intended effect.

Post your comments here:

Your comments will be displayed after verification.