Reputation: 21
This piece of code return an error.
#include<stdio.h>
#include<stdlib.h>
int* a;
a = NULL;
int main(){
printf("works");
return 0;
}
whereas this one does not...
#include<stdio.h>
#include<stdlib.h>
int* a= NULL;
int main(){
printf("works");
return 0;
}
What's the difference and why does this show the re-declaration error? If I do the same thing inside main function it works. But not outside.
Upvotes: 0
Views: 62
Reputation: 32586
a = NULL;
is a statement you can put only in the body of function
int* a= NULL;
is the definition with initialization of the global variable a
Upvotes: 1