When I compile the code below
#include<stdio.h>
int main()
{
  int a;
  int a = 10;
  printf("a is %d \n",a);
  return 0;
}
I get an error:
test3.c: In function ‘main’:
test3.c:6:5: error: redeclaration of ‘a’ with no linkage
test3.c:5:5: note: previous declaration of ‘a’ was here
But if I make the variable global then it works fine.
#include<stdio.h>
int a;
int a = 10;
int main()
{
  printf("a is %d \n",a);
  return 0;
}
Why is declaring the same global variable twice not an error, but doing that for a local variable is an error?
 
     
     
     
    