Possible Duplicate:
What is value of c, if c =a,b;
How does the initialization of int variables work in the following question:
main()
{
int i,j,k;
i=1,2;
开发者_JAVA技巧 j=(1,2);
k=(1,2),(3,4);
}
I need to be able to describe what the compiler actually does.
comma is used as separator as well as an operator. the three cases are dealt as below: first: i=1,2; assignment has higher precedence to comma(,) so i=1 is evaluated i.e. i is given value 1 and then 2 is just put there without any use. second: j=(1,2) parentheses has highest precedence so contents inside it will be evaluated first (1,2) will result to 2 and hence j is assigned value 2. third: k=(1,2),(3,4); here (1,2) and (3,4) are evaluated to 2,4 and then it is like the first expression i.e. k=2,4 so k will be assigned value 2.
hope this helps :D
精彩评论