Why is creating a variable using 'extern' a declaration and not a definition?

后端 未结 5 1243
-上瘾入骨i
-上瘾入骨i 2021-01-21 22:42

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;
5条回答
  •  情话喂你
    2021-01-21 23:05

    The four sentences are declarations, however the first three sentences are also definitions.

    Read here about the difference between declaration and definition.

    auto, static and register are modifiers for the variable. Read de documentation about them.

    extern is only declaration because you are telling the compiler that the definition of the variable or function is somewhere else - in another C module -.

    Hope it helps!

提交回复
热议问题