After seeing this answer
I have this doubt.
In my project,
I have seen some extern variables declared and defined like below:
file1.h
extern int a;
file1.c
extern int a=10;
But in the link I mentioned it says that in the c file it should be defined like:
int a = 10;
Does adding extern key word during the definition too has any purpose/meaning.
Or does it matter by the way?
It does not change the meaning.
externonly makes sense when you declare a variable. Defining a variable withexternis the same because all global variables that are not markedstaticare symbols visible to the linker by default.Note that if you didn’t want to initialise the variable, that is, not having the part
= 10, the compiler will assume thatextern int ais always a declaration and not a definition. In the same sense, havingint aglobally is always a definition and not just a declaration.