可能重複:
Redefinition allowed in C but not in C++?C中的這個雙聲明是什麼意思?
#include<stdio.h>
int i;
int i;
int main()
{
// int i;
// int i;
printf("%d\n",i);
return 0;
}
~
上面的代碼運行wihtout給予任何錯誤gcc -Wall -Werror demo.c -o demo
但是,當我取消對local
i
變量註釋掉global
i
,它給了我錯誤。
In function ‘main’:
demo.c:7:6: error: redeclaration of ‘i’ with no linkage
demo.c:6:6: note: previous declaration of ‘i’ was here
這是什麼在這裏的本地全球概念?,任何人請解釋。
它給您帶來了什麼錯誤? – Mansfield
爲什麼downvoted .. ?? – Omkant