a) 外部变量的定义与局部变量的定义相同,即int i=2;
(仅在所有函数之外)。但为什么extern int i=2;
定义太有效了?不是extern
只用在其他文件的变量声明中吗?
b) 文件 1
#include<stdio.h>
int i=3;
int main()
{
printf("%d",i);
fn();
}
文件2
int i; // although the declaration should be: extern int i; So, why is this working?
void fn()
{
printf("%d",i);
}
输出:两种情况下均为 3