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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -