Error: retraining without binding

#include<stdio.h>
int x=13; // forcing space allocation 
int x; 
int main(){
  printf("%d\n",x); 
}

The code compiled above, but the one below does not work. 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 complier as a declaration or definition depending on the context. I see that in the first case (global), but what happens in the second.

+5
source share
3 answers

Quote:

C program cannot have two global variables with the same name. C may allow multiple definitions in the same area of ​​the conditional definition rule , but in any case, all definitions will refer to the same variable.

+4
source

Because you cannot declare a local variable with the same name twice. Just don't do it.

, forward, , , .

, , .

0

: " "...

- , . , , ( ), . . . , .

, , .

- , () .

() . , -

int x;
int x;

, . . { }.

, , " " ; , struct foo;.

, . int x = 10; int x = 11; , , "redifintion of x".

0
source