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");
}- A. [debug] starting\ndone
- B. done
- C. [debug] starting
- 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
- What is printed? c int a = 10; int b = (a > 5) ? (a < 20 ? 1 : 2) : 3; printf("%d", b);
- What is printed? c #define N 5 #undef N #define N 10 int main() { printf("%d", N); }
- Assume a 64-bit LP64 ABI. What is printed? c int a = 10; int p = &a; int pp = &p; pp = 20; printf("%d %d %d", a, p, pp);
- Assume a 64-bit LP64 ABI. What is printed? c char names[] = {"Alice", "Bob", "Carol"}; char p = names; p++; printf("%s %s", p, (names + 2));
- Assume a 64-bit LP64 ABI. What is printed? c int a[5] = {10, 20, 30, 40, 50}; int p = a + 4; int q = a; printf("%ld %d %d", p - q, (p…
- Assume a 64-bit LP64 ABI. What is printed? c void modify(int arr[], int n) { for (int i = 0; i < n; i++) arr[i] += 100; } int main(void) {…