I have declared two global variables of same name in C. It should give error as we cannot declare same name variables in same storage class.
I have checked it in C++ — it gives a compile time error, but not in C. Why?
Following is the code:
int a;
int a = 25;
int main()
{
return 0;
}
Check it out at : Code Written at Ideone
I think this probably is the reason
Declaration and Definition in C
But this is not the case in C++. I think in C++, whether the variable is declared at global scope or auto scope the declaration and definition is happening at the same time.
Could anyone throw some more light on it.
Now when I define the variable two times giving it value two times it gives me error (instead of one declaration and one definition).
Code at : Two definitions now
int a;
int a;
int a;
int a = 25;
int main()
{
return 0;
}