什么为c的值,如果c = A,B; [英] What is value of c, if c =a,b;
本文介绍了什么为c的值,如果c = A,B;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int类型的= 0;
INT B = 1;
INT C = A,B;
INT D =(A,B);
解决方案
初始化之外,逗号在 A,B
是的逗号运算符和计算结果为 b
。在该行的括号涉及 D
使得这种这种情况。因此,该行实际上只是相当于:
INT D = B:
然而,在涉及 C
行了,这不是用逗号的。相反,它只是一个变量定义的列表,等同于:
INT C = A;
INT B:
(这因此不会编译,因为的重新定义b
!)
int a=0;
int b=1;
int c=a,b;
int d=(a,b);
解决方案
Outside of an initialization, the comma in a,b
is the comma operator, and evaluates to b
. The parentheses in the line involving d
makes this such a case. So that line is really just equivalent to:
int d = b;
However, in the line involving c
, this is not a use of the comma operator. Instead, it's just a list of variable definitions, equivalent to:
int c = a;
int b;
(Which consequently will not compile, due to redefinition of b
!)
这篇关于什么为c的值,如果c = A,B;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文