I've tried the following code and got an error.
int main()
{
//this will cause redefinition error
extern int x;
int x=2;
}
I've seen some answers about extern such as
Defining extern variable in main() vs. globally
and got an concept,but I am still wondering what does the compiler do in this case. Can extern be used(legal) inside some function?
update:
More specifically, since extern int x
is just a declaration,why can't I define int x? Does the compiler take extern int x
as a definition?