What is the execution logic of the expression in C? -
this question has answer here:
suppose couple of expression in c. different outputs provided.
int =2,j; j= + (2,3,4,5); printf("%d %d", i,j); //output= 2 7 j= + 2,3,4,5; printf("%d %d", i,j); //output 2 4
how execution take place in both expression , without bracket giving different outputs.
comma
operator works evaluating expressions , returning last expression.
j= + (2,3,4,5);
becomes
j= + (5); //j=7
in second expression assignment operator takes precedence on comma operator,so
j= + 2,3,4,5;
becomes
(j= + 2),3,4,5; //j=4
Comments
Post a Comment