ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
#define LOG(msg) printf("[LOG] %s\n", msg)
#ifdef DEBUG
#define TRACE(msg) LOG(msg)
#else
#define TRACE(msg)
#endif
int main(void) {
    TRACE("starting");
    printf("done");
}
  1. A. [LOG] starting\ndone
  2. B. done
  3. C. Compile-time error: DEBUG is not defined
  4. D. [LOG] starting\n

Correct answer: B. done

Since DEBUG is not defined anywhere in this file, the #else branch applies: TRACE(msg) expands to nothing at all. TRACE("starting"); therefore vanishes entirely (becoming just an empty statement), and only printf("done") actually executes, printing done.

More C Programming questions

Exams that ask this topic