After seeing this answer I have this doubt. In my project, I have seen some extern variables declared and defined like below:
file1.h
It does not change the meaning. extern
only makes sense when you declare a variable. Defining a variable with extern
is the same because all global variables that are not marked static
are 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 that extern int a
is always a declaration and not a definition. In the same sense, having int a
globally is always a definition and not just a declaration.