ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
#if 1
#define VALUE 100
#elif 0
#define VALUE 200
#else
#define VALUE 300
#endif
printf("%d", VALUE);
  1. A. 100
  2. B. 200
  3. C. 300
  4. D. Compile-time error: multiple #define VALUE in conditional branches conflict

Correct answer: A. 100

Only ONE branch of an #if/#elif/#else chain is actually compiled (the preprocessor discards the others entirely, including their #define directives). Since #if 1 is always true, only #define VALUE 100 is ever seen, so VALUE expands to 100 with no conflict.

More C Programming questions

Exams that ask this topic