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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -