ProgrammingHardTCS NQT · Product company OA
What is printed?
What is printed?
#define MAX(a, b) a > b ? a : b
int x = 3, y = 7;
printf("%d", 2 * MAX(x, y));- A. 7
- B. 6
- C. 3
- D. 14
Correct answer: A. 7
The expansion is 2 * x > y ? x : y. Multiplication binds tightest, so the condition is (2 * 3) > 7, which is false, and the result is y = 7, not twice it. Parenthesising the whole body, ((a) > (b) ? (a) : (b)), gives the intended 14.
More C Programming questions
- Assume IEEE-754 single-precision float with float arithmetic done in float. Which loops terminate? c int c1 = 0, c2 = 0; for (float f = 0…
- What is printed? c struct Shape { int w, h; int (area)(struct Shape ); }; int rect(struct Shape s) { return s->w s->h; } int tri(struct…
- What is printed? c int i = 0, s = 0; top: s += i; if (++i < 5) goto top; printf("%d %d", s, i);
- What is printed? c int calls = 0; int mx(int a, int lo, int hi) { calls++; if (lo == hi) return a[lo]; int m = (lo + hi) / 2; int l =…
- What is printed? c int a[] = {1, 2, 3}, p = a; int x = ++p++; int y = p++ 10; printf("%d %d %d %d", x, y, a[0], p);
- What is printed? c int x = 10; int p = &x, pp = &p; printf("%d", pp + p 2);