ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
#define DEBUG 0
...
#ifdef DEBUG
printf("on ");
#endif
#if DEBUG
printf("trace");
#endif- A. Nothing
- B. on
- C. on trace
- D. trace
Correct answer: B. on
#ifdef only asks whether the macro is defined, and DEBUG is defined (as 0), so "on " is compiled in. #if evaluates the value, 0, which is false, so the trace line is removed.
More C Programming questions
- In C, with int i = 1, a[5];, which statement has undefined behaviour?
- Compiled as C with 4-byte int, what is printed? c printf("%zu %zu", sizeof('A'), sizeof(char));
- What is printed? c int x = 1; { int x = 2; { x = 3; } printf("%d ", x); } printf("%d", x);
- With 4-byte int, what is printed? c int a[5]; printf("%td %td", (char )(a + 1) - (char )a, (char )(&a + 1) - (char )a);
- What is printed? c printf("%d", 010 + 0x10 + 10);
- What happens? c for (unsigned int i = 3; i >= 0; i--) printf("%u ", i);