ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
#define DEBUG 0
...
#ifdef DEBUG
    printf("on ");
#endif
#if DEBUG
    printf("trace");
#endif
  1. A. Nothing
  2. B. on
  3. C. on trace
  4. D. trace

Correct answer: B. on

#ifdef only asks whether the macro is defined, and DEBUG is defined (as 0), so "on " is compiled in. #if evaluates the value, 0, which is false, so the trace line is removed.

More C Programming questions

Exams that ask this topic