ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
#define MAX_SIZE 100
#if MAX_SIZE > 50
const char *label = "large";
#else
const char *label = "small";
#endif
printf("%s", label);
  1. A. large
  2. B. small
  3. C. Compile-time error: #if cannot compare a macro to a number
  4. D. MAX_SIZE

Correct answer: A. large

#if directives are evaluated by the PREPROCESSOR using integer constant arithmetic; MAX_SIZE expands to 100 before the comparison, so MAX_SIZE > 50 becomes 100 > 50, which is true, so the #if branch is kept (label = "large") and the #else branch is discarded entirely.

More C Programming questions

Exams that ask this topic