区别" INT I = 1,2,3"和" INT I =(1,2,3)" - 逗号分隔符变量声明 [英] Difference between "int i=1,2,3" and "int i=(1,2,3)" - variable declaration with comma operator
问题描述
-
INT I = 1,2,3;
-
INT I =(1,2,3);
-
INT I; I = 1,2,3;
什么是这些语句之间的区别?我不能让任何特定的理由。
声明1结果:编译错误。
=经营者有较高的precedence比,运营商。
逗号充当这里的分隔符。编译器创建一个整型变量'我'和'1'对其进行初始化。
编译器未能创建整数变量'2'为'2'是不是一个有效indentifer
声明2结果:I = 3
()经营者具有较高的precedence比=。所以,第一,支架运营商进行评估。从左至右'()'操作符被操作。但它始终是最后那个被分配的结果。
声明3:结果:I = 1
=经营者有较高的precedence比,运营商。所以'我'会被'1'初始化。 '2'和'3'只是不断前pression。所以没有任何效果。
int i=1,2,3;
int i=(1,2,3);
int i; i=1,2,3;
What is the difference between these statements? I can't get to any particular reason for it.
Statement 1 Result : Compile error.
'=' operator has higher precedence than ',' operator. comma act as a separator here. the compiler creates an integer variable 'i' and initializes it with '1'. The compiler fails to create integer variable '2' as '2' is not a valid indentifer.
Statement 2 Result: i=3
'()' operator has higher precedence than '='. So , firstly, bracket operator is evaluated. '()' operator is operated from left to right. but it is always the result of last that gets assigned.
Statement 3: Result: i=1
'=' operator has higher precedence than ',' operator. so 'i' gets initialized by '1'. '2' and '3' are just constant expression. so have no effect .
这篇关于区别" INT I = 1,2,3"和" INT I =(1,2,3)" - 逗号分隔符变量声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!