gpt4 book ai didi

c - 使用非常量初始值设定项定义全局变量

转载 作者:太空狗 更新时间:2023-10-29 17:16:52 24 4
gpt4 key购买 nike

#include <stdio.h>

int i=10;
int j=i;
int main()
{
printf("%d",j);
}

我收到一条错误消息,指出初始化元素不是常量?这背后的原因是什么?

最佳答案

What is the reason behind this?

C(与 C++ 不同)不允许使用非常量值初始化全局值。

C99 标准:第 6.7.8 节:

All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals.

关于c - 使用非常量初始值设定项定义全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13785250/

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