Not able to understand the reason for output

后端 未结 3 1762
粉色の甜心
粉色の甜心 2021-01-14 04:31

I am running a code snippet. But I am not able to understand the code and the output that it is producing.

#include 
int main()  
{ 
  int a,          


        
3条回答
  •  失恋的感觉
    2021-01-14 05:06

    1. When you have a comma, the expression is evaluated as the right parameter, that's why d=(a,b); is evaluated as d=b.
    2. = has a higher precedence over the comma, so the expression c=a,b; is evaluated as (c=a),b;

    Not part of the answer, but worth mentioning that the whole c=a,b; expression, is evaluated as b, not a, e.g. if you write d=(c=a,b); you get c=a AND d=b;

提交回复
热议问题