Comma in initialization / declaration variable

I came across a piece of code that looks like this:

void check() { int integer = 7; //integer2 is not declared anywhere int check = integer, integer2; //after running //check = 7 //integer = 7 //integer2 = 0 } 

What is the purpose of the comma here?

+6
source share
1 answer

Comma variable declarations simply let you declare a second variable of the same type. This is equivalent to:

 int check = integer; int integer2; 

Concerning:

 //integer2 is not declared anywhere 

Yes it is; Right here! This is an integer2 .

+7
source

Source: https://habr.com/ru/post/974966/


All Articles