590 views

2 Answers

Best answer
4 votes
4 votes

That is how C grammar is written. In declaration and function argument list comma acts as separator but in expressions it acts as comma operator. 

selected by
0 votes
0 votes

int i=1,2,3;

here = is high  precedence than , ===> statement look like as int (i=1),2,3; ==> This statement has three declarations 

i.e.,  int i=1;

        int 2;   -----> Error due to variable name can not starts with digits

       int 3;    -----> Error due to variable name can not starts with digits

therefore you can try this statement it can work int i=1,v2,v3;


i=1,2,3 it acts an operator --- 

this statement is equivalent to (i=1),2,3;

$($ (i=1),2,3$)$;

this can't lead the error why because it is a expression statement in C


i=(1,2,3) here comma acts as a operator... it have left to right associativity and it is a sequence point also...

for understanding sequence point  let consider the example

int k=10,m=11,n;

n=(k++,++m,k++) ==> k=11 m=12 k=11 ===> n=11 but after completion of statement k=12  

edited by

Related questions

0 votes
0 votes
1 answer
3
radha gogia asked Jul 21, 2015
305 views
char ch;scanf("%c",&ch) // after I do scanning of this variable then after I press enter key then it gets stored inside the buffer so can we print this enter key .Since d...
1 votes
1 votes
1 answer
4