ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
#if defined(DEBUG)
    #define LOG(msg) printf("DEBUG: %s\n", msg)
#else
    #define LOG(msg)
#endif
int main(void) {
    LOG("hello");
    printf("done");
}
  1. A. done (assuming DEBUG is not defined, LOG expands to nothing)
  2. B. DEBUG: hello\ndone
  3. C. Compilation error: LOG needs an argument even when empty
  4. D. hello done

Correct answer: A. done (assuming DEBUG is not defined, LOG expands to nothing)

Without a #define DEBUG earlier, the #else branch is active, where LOG(msg) expands to nothing at all (an empty replacement, which is legal), so the LOG("hello"); line vanishes entirely and only "done" prints.

More C Programming questions

Exams that ask this topic