The difference between extern int a; extern int a = 42;

While I read the answers Using the 'extern' keyword when defining a variable

One user answered this question.

 extern int a;       //  not a definition 
 extern int a = 42;  //  definition 

I expected that both are not definitions, but declarations. I thought both statements say that the variable is defined outside the function, and we must use the extern keyword to use it. Is it a mistake from him or is this really a definition? I know that

extern int a; // variable is already defined but its outside the function
extern int a=42 ; //I guess a variable is assigned a value but not a definition 

but this statement

extern int a = 42; // user said its a definition and now i got  confused

Please cleanse me of them.

+5
source share
3 answers

, , extern. extern , , static, .

, .

+7

extern int a; - . .

extern int a = 42; - . int a 42.

+5

main(),

extern int a; //This is a declaration

extern int a=42; //This is a definition
0

All Articles