When I compile the code below
#include
int main()
{
int a;
int a = 10;
printf(\"a is %d \\n\",a);
return 0;
}
I get
The other reason I could think of is that un-initialized global variables are stored in the BSS (Block Structured Segment) where are the global variables that are initialized are stored in Data Segment.
I am guessing that there is some kind of a name space resolution and when there is a conflict the variable in the Data segment overrides the one in the Block Structured Segment.
if you were to declare
int a =5 int a = 10
in the global scope (both in the data segment) there would be conflict as expected.