If I declare i
to be a global variable twice, then it works fine:
#include <stdio.h>
int i;int i;
int main(void)
{
printf("%d",i);
return 0;
}
But not if I declare it locally (twice)
#include <stdio.h>
int main(void)
{
int i;int i;
printf("%d",i);
return 0;
}
Error
error: redeclaration of ‘i’ with no linkage
Also, if in the 1st case I initialize i to some value i=1
, then also it gives error error: redefinition of ‘i’
Why is does it exhibit such a behaviour ?
Thanks!