ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
#define DEBUG 0
int main(void) {
#if DEBUG
printf("debug mode\n");
#else
printf("release mode\n");
#endif
return 0;
}- A. Compilation error: #if requires defined()
- B. debug mode
- C. release mode
- D. Both lines print
Correct answer: C. release mode
#if evaluates DEBUG as an integer constant expression (0, since it's literally defined as 0, not merely checked for existence with defined()); since 0 is falsy, the #else branch is compiled instead, printing "release mode".
More C Programming questions
- Two files are compiled and linked together. What happens? c / file1.c / static int counter = 0; void inc(void) { counter++; } / file2.c /…
- What is printed? c int x = 10; void f(void) { int x = 20; { int x = 30; printf("%d ", x); } printf("%d ", x); } int main(void) { f()…
- What is printed? c void f(void) { register int i; int p = &i; p = 5; printf("%d", i); }
- What is printed? c int x = 100; void f(void) { extern int x; printf("%d", x); } int main(void) { f(); }
- What is printed? c void f(void) { printf("%d ", x); } int x = 42; int main(void) { f(); }
- What is printed? c int x = 5; void modify(void) { x = 10; } int main(void) { int x = 20; modify(); printf("%d %d", x, ::x == 5); }