ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
#define MAX_SIZE 100
#if MAX_SIZE > 50
const char *label = "large";
#else
const char *label = "small";
#endif
printf("%s", label);- A. large
- B. small
- C. Compile-time error: #if cannot compare a macro to a number
- D. MAX_SIZE
Correct answer: A. large
#if directives are evaluated by the PREPROCESSOR using integer constant arithmetic; MAX_SIZE expands to 100 before the comparison, so MAX_SIZE > 50 becomes 100 > 50, which is true, so the #if branch is kept (label = "large") and the #else branch is discarded entirely.
More C Programming questions
- Assume 32-bit int. What is printed? c int x = 10; int p = &x; p += 5; p = 2; printf("%d", x);
- What happens when this runs? c int fibonacci(int n) { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2); } int main(void) {…
- Assume 32-bit int. What is printed? c int arr[3] = {1, 2, 3}; int total = 0; int i; for (i = 0; i < 3; i++) total = total + arr[i]…
- Assume a 64-bit LP64 ABI. What is printed? c int createZeroed(int n) { int arr = calloc(n, sizeof(int)); return arr; } int main(void) {…
- Assume 32-bit int. What is printed? c int x = 5; int y = x-- - --x; printf("%d %d", x, y);
- Assume a 64-bit LP64 ABI. What is printed? c struct Pair { int first; int second; }; struct Pair makePair(int a, int b) { return (struct…