c-program-preprocesor

Can someone explain how will the preprocessor expand the following the code?

#define USEFLOAT 0
int N;
#if USEFLOAT
float X;
#else
double X;
#endif

I have read the chapter on preprocessor several times and was unable to make a choice from these answers.
a.int N
b.int N;
double X;
c. int N;
float X;


Comments

  • : Can someone explain how will the preprocessor expand the following
    : the code?
    :
    : #define USEFLOAT 0
    : int N;
    : #if USEFLOAT
    : float X;
    : #else
    : double X;
    : #endif
    :
    : I have read the chapter on preprocessor several times and was
    : unable to make a choice from these answers.
    : a.int N
    : b.int N;
    : double X;
    : c. int N;
    : float X;
    :
    :

    I think 0 evals to false in the preprocessor.
    Also, you should take away the obviusly wrong answers.
  • Yep, the preprocessor uses the same boolean logic as common C code.

    #if 0

    and

    if(0)

    are both always false.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion