如题所述
逗号运算符用于连接各表达式,优先级要小于“=”即赋值运算符。
例:int a = 5, b = 6, c = 7; //可以如此定义变量;
int example = (a++, b + 1, ++c);
//由逗号运算符连接的表达式返回的将是最右边的表达式的值,所以example的值为8;
int example_2 = (example = ++c, ++b, ++a);
//逗号运算符的优先级小于赋值运算符,所以example的值为9,example_2的值为7;追问
例:int a = 5, b = 6, c = 7; //可以如此定义变量;
int example = (a++, b + 1, ++c);
//由逗号运算符连接的表达式返回的将是最右边的表达式的值,所以example的值为8;
int example_2 = (example = ++c, ++b, ++a);
//逗号运算符的优先级小于赋值运算符,所以example的值为9,example_2的值为7;追问
谢谢!
温馨提示:答案为网友推荐,仅供参考