I understand the terms declaration and
definition as
below.
Declaration:
This is just a heads up to the compiler that a variable of specified
"name" and "type" exists in
the code. So that it can be defined/assigned at later point of
time
Definition:
This is the process where an instance of the type is created by allocating a suitable
space of memory.
int var;
//Declaration and Definition-Agreed!!!
extern int var; //Declaration only
?
static int var; //Declaration only
?
My mind refuses to
agree the second and third ones as declaration only
statements. Because in many references I see, "extern and static variables
are automatically initialized to zero upon memory allocation". And as you
see in following code.
#include
int main()
{
static int
i;
printf("%d\n",i);
return
0;
}
The
output is 0. So Here it looks like the static int i; is
declaration,definition and auto initialization statement. So please add your
justification for this
No comments:
Post a Comment