int a = 0;
This code can be read either: declaration of a or definition of a, right?
int a = 0;
This code can be read either: declaration of a or definition of a, right?
declaration of a or definition of a right?
Note that every definition is necessarily a declaration in C++, but not the other way round. That is, not every declaration is a definition.
Thus,
int a = 0; // A definition and hence also a declaration
The above is both a definition and also a declaration.
On the other hand, if you were to write:
extern int a; // This is a nondefining declaration
The above statement extern int a;
is a declaration that is not a definition (aka a nondefining declaration)
Moreover,
extern int a = 0; // This is a definition and hence also a declaration even when we have used extern!
Note that even though we have used extern
in the above statement, the presence of the initializer 0
makes this a definition and hence also a declaration.