extern的一个小问题

SeeSeaBee SeeSeaBee 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
写了一段代码
test.c
#include<stdio.h>

int main()
{
extern char filename[]="file";
char filename[]="file";
printf("%s\n",filename);
return 0;
}
以上的代码编译时会error,表明filename重复定义了
但是如果把代码改称下面的:
test.c
#include<stdio.h>

extern char filename[]="file";
char filename[]="file";
int main()
{
printf("%s\n",filename);
return 0;
}
程序可以正常编译和执行
不太明白原因,请大家解释一下
ps:我在debain下gcc编译
...全文
评论 19
收藏 已收藏
分享
返回顶部
SeeSeaBee
C语言 70,039 成员 243,237 内容