ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
#define VERSION 2
#if VERSION >= 2
const char *msg = "new";
#else
const char *msg = "old";
#endif
int main(void) { printf("%s", msg); }
  1. A. new
  2. B. old
  3. C. Compilation error: #if cannot compare macros
  4. D. Undefined behaviour

Correct answer: A. new

#if evaluates constant integer expressions at preprocessing time; VERSION expands to 2, and 2 >= 2 is true, so the first branch (msg = "new") is compiled in and printed.

More C Programming questions

Exams that ask this topic