ProgrammingVery hardTCS NQT · Infosys · Product Company SDE

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int main(void) { #define MAX(a, b) ((a) > (b) ? (a) : (b)) int x = 5, y = 8; int m = MAX(x++, y); printf("%d %d", m, x); return 0; }

  1. A. 8 6
  2. B. 8 7
  3. C. 9 7
  4. D. 8 5

Correct answer: A. 8 6

MAX(a,b) expands to ((a) > (b) ? (a) : (b)). Substituting gives ((x++) > (y) ? (x++) : (y)); x++ appears in the condition, evaluating to 5 (then x becomes 6) which is not greater than y=8, so the false branch (y=8) is chosen; x ends at 6, since the macro's true-branch x++ is never reached.

More C Programming questions

Exams that ask this topic