ProgrammingHardAccenture · Cognizant pattern

What is printed?

What is printed?
#if defined(DEBUG) && !defined(RELEASE)
    #define LOG(x) printf("[debug] %s\n", x)
#else
    #define LOG(x)
#endif
int main() {
    LOG("starting");
    printf("done");
}
  1. A. [debug] starting\ndone
  2. B. done
  3. C. [debug] starting
  4. D. Compilation error: LOG(x) with no body is invalid

Correct answer: B. done

Since DEBUG is not defined (not passed via -DDEBUG), the #else branch is active, defining LOG(x) as an empty macro — so LOG("starting") expands to literally nothing, and only 'done' ever prints.

More C Programming questions

Exams that ask this topic