[英]Comma in variable initialization/declaration
I've stumbled upon a piece of code that look as follows: 我偶然发现了一段代码如下:
void check()
{
int integer = 7;
//integer2 is not declared anywhere
int check = integer, integer2;
//after running
//check = 7
//integer = 7
//integer2 = 0
}
what's the purpose of the comma here? 逗号的目的是什么?
Comma on variable declarations simply allows you to declare a second variable of the same type. 变量声明上的逗号只允许您声明相同类型的第二个变量。 It is equivalent to:
它相当于:
int check = integer;
int integer2;
As for: 至于:
//integer2 is not declared anywhere
Yes it is; 是的; right here!
就在这儿! This is the declaration of
integer2
. 这是
integer2
的声明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.