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");
}- A. done (assuming DEBUG is not defined, LOG expands to nothing)
- B. DEBUG: hello\ndone
- C. Compilation error: LOG needs an argument even when empty
- 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
- What is printed? c #define VERSION 2 #if VERSION >= 2 const char msg = "new"; #else const char msg = "old"; #endif int main(void) {…
- What is printed? c #define TWICE(x) (2 (x)) #define FOURTIMES(x) TWICE(TWICE(x)) printf("%d", FOURTIMES(3));
- What is printed? c #define ISEVEN(n) ((n) % 2 == 0) int a = 7; printf("%d", ISEVEN(a + 1));
- What is printed? c #define EMPTY #define SEMI ; int x = 5 EMPTY SEMI printf("%d", x);
- What is printed? c #define PRINT(x) printf(#x " = %dn", x) int main(void) { int value = 42; PRINT(value); }
- What is printed? c #define MIN(a, b) ((a) < (b) ? (a) : (b)) int calls = 0; int next(void) { calls++; return calls; } int main(void) { int…