What is the execution logic of the expression in C? -


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

Popular posts from this blog

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -