Operator precedence in C for the statement z=++x||++y&&++z

后端 未结 4 1576
感情败类
感情败类 2021-01-16 09:48

I was studying operator precedence and I am not able to understand how the value of x became 2 and that of y and z is

4条回答
  •  天命终不由人
    2021-01-16 10:44

    x=y=z=1
    z=++x||++y&&++z
    

    is equivalent to

    x=y=z=1
    z=((++x)||((++y)&&(++z)));
    

    Since ++x returns 2, which is nonzero, the ++y && ++z branch is never executed, and thus the code is equivalent to:

    x=y=z=1;
    z=(++x)||(anything here);
    

提交回复
热议问题