ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int i = 3;
int r = MAX(i++, 2);
printf("%d %d", r, i);- A. 3 4
- B. 4 4
- C. 3 5
- D. 4 5
Correct answer: D. 4 5
The macro expands to ((i++) > (2) ? (i++) : (2)). The condition reads 3 and increments i to 4 (the ?: has a sequence point after its condition), then the chosen branch i++ yields 4 and makes i 5. A function MAX would evaluate i++ once.
More C Programming questions
- What is printed? c unsigned int i; int count = 0; for (i = 3; i >= 0; i--) { if (++count == 5) break; } printf("%d %u", count, i); /…
- What is printed? c printf("%d %d %d %d", -17 / 5, -17 % 5, 17 / -5, 17 % -5);
- What is printed? c int i = 5; sizet s = sizeof(i++); printf("%zu %d", s, i); / 4-byte int /
- What is printed? c char names[] = {"Ann", "Bob", "Cy"}; printf("%c %s %zu", names[1][0], names[2], strlen(names[0]));
- What is printed? c int n = 40; / binary 101000 / printf("%d %d %d", n & (n - 1), n & -n, (n & (n - 1)) == 0);
- What is printed? c int a[] = {3, 1, 4, 1, 5}; int sum(int n) { return n == 0 ? 0 : a[n - 1] + sum(n - 1); } int main(void) { printf("%d"…