Machine-translated by Google. Questions are authored in English.
Top

Discussion

Will the program compile successfully?

#include <stdio.h>
#define X (4+Y)
#define Y (X+3)

int main()
{
    printf("%d\n", 4*X+2);
    return 0;
}

 

  • A.Yes
  • B.No

Answer: B

Correct answer: No

The two definitions refer to each other, and the preprocessor refuses to expand a macro recursively inside its own expansion. So the expansion of X stops with a bare Y (or the other way about) left in the text, and the compiler then meets an undeclared identifier. Mutually recursive macros are always a mistake.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.