#include<stdio.h>
int x=13; // forcing space allocation
int x;
int main(){
printf("%d\n",x);
}
The code above compiles but the one below does not. why ?
#include<stdio.h>
int main(){
int x=13; // forcing space allocation
int x;
printf("%d\n",x);
}
i was told that int x ; can be interpreted by the complier as a declaration or definition depending on the context . i can see that in the first case(global one) but what happens in the second.
Quoting:
You can't have two global variables with the same name in C program. C might allow multiple definitions in the same file scope through the tentative definition rule, but in any case all definitions will refer to the same variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With