Question discussion

What is the output of the following C program?#include #define MAX(a, b) ((a) > (b) ? (a) : (b)) int main() { int i = 5, j = 3; int m = MAX…

1737Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int main() {
    int i = 5, j = 3;
    int m = MAX(i++, j++);
    printf("%d %d %d", m, i, j);
    return 0;
}
  • A5 6 4
  • B6 7 4
  • C6 6 4
  • D5 7 4
Correct answer: B

Explanation

The macro evaluates ((i++) > (j++) ? (i++) : (j++)); the condition 5 > 3 is true, so the second i++ is evaluated too, giving m = 6, i = 7 and j = 4.

Discussion 0

Nobody has replied yet. Start the discussion!