I created a struct:
struct number_struct
{
int i;
float f;
} struct_a;
Thus struct_a is of type number_struct.
Later in int main I write:
number_struct struct_a = { 0 };
number_struct struct_b = { 0 };
The confusion is that since I have declared struct_a twice, I would expect a message from visual studio saying that it has been declared twice, aka name collision. Why does this not occur? It does occur if I declare struct_b twice but within the main routine.
Besides this, if I do the following without initializing the structs:
std::cout << struct_a.i << "\t" << struct_b.i << std::endl;
std::cout << struct_a.f << "\t" << struct_b.f << std::endl;
I get a runtime error saying that the sturct is being used without initialization. Why does the compiler not initialize the struct (and standard type variables) to 0 automatically?