I came across the following problem while reading ...just cant get the logic behind this.
auto int c;
static int c;
register int c;
extern int c;
The last one with extern
does not define storage for c
. It merely indicates that c
exists somewhere and the linker should be able to resolve it to some global c
defined elsewhere.
If you compiled and linked a single .c file and tried to use the last c
you'd have a linker error. With the the first 3 c
s you would not as they have substance (they've been defined) in the current compilation unit.
If you'd like to learn more about extern
and declaration vs definition here's a good article on the topic. To quote from that article:
Declaration of a variable/function simply declares that the variable/function exists somewhere in the program but the memory is not allocated for them