C Programming - C Preprocessor - Discussion

2. 

Preprocessor directive #undef can be used only on a macro that has been #define earlier

[A]. True
[B]. False

Answer: Option A

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


Andras Joo said: (Oct 1, 2010)  
Partially true.

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

Works perfectly though without the intended effect.

Dmitri said: (Aug 27, 2011)  
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.

Susee said: (Apr 5, 2012)  
Yes. Undef will work without define statement.

-susi.

Rafaelsorel said: (Jun 12, 2013)  
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;
}

}}}

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.