k = MAX(i++, ++j);
This code will be replaced by
k = (i++)>(++j)?(i++):(++j);
when checking the condition (i++)>(++j)
, i
is post increment(after the operation it will increment) and j
is pre-increment( increment the j
and substitute it). so while checking it will take (10) > (6), it is true! after this check i
will become 11.
k = (i++)>(++j)?(i++):(++j); --> k = (i++)>(++j)?((11)++):(++j); // note after condition check i becomes 11.
// due to post increment after assigning the value to k, i will be incremented to 12. but the last ++j wont excuted.
So you will get output 12 6 11
.
else you can rewrite the k = (i++)>(++j)?(i++):(++j);
as
if((i++)>(++j)) //when condition check i=10, j=6 after check i=11,j=6
k=i++; // k= 11++; after assigning 11 to k i will be incremented to 12
else
k=++j; // this wont be executed