Why does this code not throw a compilation error for y being undeclared?
int x = 10, y;
printf("%d", y);
There's no expression like int y;. In my case, the console print out is 32764, which seems to just be uninitialized memory. Looking at the assembly code for the first line, it's the same whether the , y is there or not, even if y is used in the print statement.
Expected to see
error: use of undeclared identifier 'y' printf("%d", y);
This:
Is not an instance of the comma operator. The
,is part of the grammar of a declaration which allows multiple variables to be declared on the same line. Specifically, it declaresxand initializes it to 10 and declaresywhich is uninitialized. It's equivalent to:Had you instead done this:
Then you would have an instance of the comma operator and an error for an undeclared identifier.