This code works fine when I re-declare the variable x
in global scope:
#include <stdio.h>
#include <stdlib.h>
int x = 12;
int x;
int main() {
printf("%d", x);
return 0;
}
However, this code gives me an error: "redeclaration of 'x' with no linkage"
#include <stdio.h>
#include <stdlib.h>
int main() {
int x = 12;
int x;
printf("%d", x);
return 0;
}
I have learned that redefinition is not allowed more than once but redeclaration is allowed. Is this true only for global variables?