ProgrammingVery hardGATE CS
What is printed?
What is printed?
#include <stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int main(void) {
int i = 3, j = 5;
int m = MAX(i++, j++);
printf("%d %d %d", m, i, j);
return 0;
}- A. 5 4 7
- B. 5 4 6
- C. 6 4 6
- D. 6 4 7
Correct answer: D. 6 4 7
The macro expands to ((i++) > (j++) ? (i++) : (j++)). The condition 3 > 5 is false after i = 4 and j = 6; the ?: operator has a sequence point after its first operand, so the false branch evaluates j++ again, yielding 6 and leaving j = 7. Hence m = 6, i = 4, j = 7.
More C Programming questions
- What is printed? c #include <stdio.h> int f(int n) { static int c = 0; c++; if (n >= 2) { f(n - 1); f(n - 2); } return c; } int main(void)…
- What is printed? Assume pointers are 8 bytes and the string literal's characters are those between the quotes. c #include <stdio.h>…
- What is the exact output? c #include <stdio.h> int main(void) { int n = printf("%d%d", 12, 345); printf("|%d", n); return 0; }
- What is printed? Assume int is 4 bytes and pointers are 8 bytes. c #include <stdio.h> void f(int a[10]) { printf("%zu ", sizeof a); } int…
- What is printed? Assume the usual ABI: char 1 byte, short 2, int 4, with each member aligned to its own size and the struct padded to a…
- What is printed? c #include <stdio.h> int main(void) { char s[] = "abcd"; char p = s; (p)++; p++ += 2; ++p; p[1]--; printf("%s", s)…