gpt4 book ai didi

C 全局变量代码给出编译错误

转载 作者:行者123 更新时间:2023-11-30 21:15:18 25 4
gpt4 key购买 nike

所以我是 c 的新手,编写了一些代码,但我不确定为什么当我尝试运行它时会收到错误。

 int GlobalVariable=0;
int main()
{
int LocalVariable=0; //can be used within main()
dis();
printf(GlobalVariable);
return 1;
}

int dis()
{
GlobalVariable=5; //Can be accessed in any functions and made changes to it
}

最佳答案

这是 printf 函数的原型(prototype):

int printf(const char * restrict format, ...);

看看你正在输入什么:

int GlobalVariable=0;
printf(GlobalVariable);

关于C 全局变量代码给出编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41906012/

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