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

Discussion

Will the program compile successfully?

#include <stdio.h>

int main()
{
    #ifdef NOTE
        int a;
        a=10;
    #else
        int a;
        a=20;
    #endif
    printf("%d\n", a);
    return 0;
}

 

  • A.Yes
  • B.No

Answer: A

Correct answer: Yes

NOTE is not defined, so the #ifdef branch is deleted and only the #else branch reaches the compiler. Exactly one declaration of a therefore survives, and the program compiles and prints 20. Had both branches been kept, the duplicate declaration would have been an error - which is the point of the example.

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

Post your comment

Please log in or register to post a comment.