参见英文答案 >
Multiple declarations and definitions3
当我编译下面的代码
当我编译下面的代码
- #include<stdio.h>
- int main()
- {
- int a;
- int a = 10;
- printf("a is %d \n",a);
- return 0;
- }
我收到一个错误:
- 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
但是如果我使变量为全局,那么它可以正常工作.
- #include<stdio.h>
- int a;
- int a = 10;
- int main()
- {
- printf("a is %d \n",a);
- return 0;
- }