I'm not really sure am I right, but i think that: in the line static int k;
variable is declared and defined (k
is initialized by default to 0); in the next line static int k = 31;
I initialized k
to 31 (why this is not redefinition?); in the next line nothing is actually changed because it's just another declaration of k
- i've read somewhere that multiple declarations are allowed sometimes (if you can tell me when and where).
static int k;
static int k = 31;
static int k;
int main()
{
static int k;
static int k = 21;
static int k;
printf("%d", k);
return 0;
}
Why I didn't get an error for the line static int k = 31;
for redefinition? On the other hand, if it works properly for global variable k
why I'm getting redeclaration error for the line static int k = 21;
for local k
. Can someone explain this so I can understand even if I'm just a beginner in C?