gpt4 book ai didi

c - 错误 : Redeclaration with no linkage

转载 作者:太空狗 更新时间:2023-10-29 15:04:48 30 4
gpt4 key购买 nike

#include<stdio.h>
int x=13; // forcing space allocation
int x;
int main(){
printf("%d\n",x);
}

上面的代码可以编译,但下面的代码不能。为什么?

#include<stdio.h> 
int main(){
int x=13; // forcing space allocation
int x;
printf("%d\n",x);
}

有人告诉我 int x ;编译器可以根据上下文将其解释为声明或定义。我可以在第一种情况(全局情况)中看到这一点,但在第二种情况下会发生什么。

最佳答案

Quoting:

You can't have two global variables with the same name in C program. C might allow multiple definitions in the same file scope through the tentative definition rule, but in any case all definitions will refer to the same variable.

关于c - 错误 : Redeclaration with no linkage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8124682/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com