Hello,
I just cant figure out why i get this output. When i run this program, i get the output as 11 11 11, how ? shouldn't it be 11 10 10 ?? Please explain...

#include<stdio.h>
#define MAX(x,y) (x)>(y)?(x):(y)
int main()
{
int i=10,j=9,k=0;
k=MAX(i++,++j);
printf("%d %d %d",i,j,k);
}

That's not your macro. The macro is only 1 line.
Try it again.

Study the definition of a magro again.

Edited
by WaltP

0

I_m_rude

since i is in brackets, then i will be incremented, also j will be incremneted. then 11>10, then ++j will again executed, so k is assigned 11. so all are 11 at this time.

#include<stdio.h>
#define MAX(x,y) (x)>(y)?(x):(y)
int main()
{
int i=10,j=9,k=0;
k = (i++) > (++j) ? i++ : ++j;
printf("%d %d %d",i,j,k);
return 0;
}

Yes, i get 11 11 11, im begining to understand, i++ is done first, followed by ++j since they are given in braces, 10 is not greater than 10 so k=++j, so k=11, in the next step the incremented value of i and j,k are displayed as 11 11 11, am i right ??