Im new to C programming and having trouble understanding the output of this program.
Will really appreciate if someone can explain the logic of the output
#define MAX(x,y) (x)>(y)?(x):(y)
void main( )
printf(%d %d %d %d,i,j,k);
I believe it should be undefined behavior. You have multiple increments and decrements in a single execution point. That means the output is undefined:
k = (i++) > (j++) ? (j++) : (i++);
the output im getting is 12 6 11.dont know how?
?: is a sequence point, so you should be OK on that front.
Perhaps try to write the statement as a rather more verbose if / else statement instead?
It will help you to see when things get incremented, compared, assigned.
a > b ? true_exp : false_exp;
Take note that only either true_exp or false_exp is evaluated.
(i++) > (j++) ? (i++) : (j++)
If i++ is greater than j++, only i++(true_exp) is evaluated. causing i value incremented twice.