-5
#define man(x,y)((x)>(y))?(x):(y);

int main()
{
    int i=10,j,k;
    j=5;
    k=0;

    k=man(++i,j++);
    printf("%d %d %d",i,j,k);
    return 0;
}

The output is:

12 5 12

Can anyone make it clear as to how the value of i,k is 12 and not 11.

dragosht
  • 3,237
  • 2
  • 23
  • 32
  • 1
    expand the macro by hand and see how it looks. – Sneftel Jul 24 '14 at 07:50
  • Unrelated to the question, but why are you writing the initialization so weirdly? Why not simply `int i = 10, j = 10; int k = man(++i, j++);`? That way it's readable and economical. – Kerrek SB Jul 24 '14 at 08:32

1 Answers1

0

Explanation:

The macro MAN(x, y) ((x)>(y)) ? (x):(y); returns the biggest number of given two numbers.

Step 1: int i=10, j=5, k=0; The variable i, j, k are declared as an integer type and initialized to value 10, 5, 0 respectively.

Step 2: k = MAN(++i, j++); becomes,

=> k = ((++i)>(j++)) ? (++i):(j++);

=> k = ((11)>(5)) ? (12):(6);

=> k = 12

Step 3: printf("%d, %d, %d\n", i, j, k); It prints the variable i, j, k.

In the above macro step 2 the variable i value is incremented by 2 and variable j value is incremented by 1.

Hence the output of the program is 12, 6, 12

Setu Kumar Basak
  • 11,460
  • 9
  • 53
  • 85