Please Explain Comma Operator in this Program

前端 未结 3 1991
迷失自我
迷失自我 2020-11-28 14:45

Please explain me the output of this program:

int main()
{    
    int a,b,c,d;  
    a=10;  
    b=20;  
    c=a,b;  
    d=(a,b);  
    printf(\"\\nC= %d\"         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 15:10

    Well, this is about operator precedence:

    c=a,b
    

    is

    equivalent to

    (c=a),b
    

    The point is, the "," operator will return the second value.

    Thus

    c=a,b
    

    assigns a to c and returns b

    d=(a,b) 
    

    returns b and assigns it to d

提交回复
热议问题