gpt4 book ai didi

c - 错误 : variably modified 'd' at file scope

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

代码 1:-

int size;

struct demo
{
int a;
};

int main()
{
scanf("%d",&size);
struct demo d[size];
return 0;
}

这段代码工作正常。

代码 2:-

int size;

struct demo
{
int a;
};

int main()
{
scanf("%d",&size);
return 0;
}

struct demo d[size];

此代码显示错误:-

error : variably modified 'd' at file scope

为什么这样的错误出现在 Code 2Code 1 运行正常?

最佳答案

在代码 2 中,您的结构数组驻留在定义中的数据段中

A data segment is a portion of virtual address space of a program, which contains the global variables and static variables that are initialized by the programmer. The size of this segment is determined by the values placed there by the programmer before the program was compiled or assembled, and does not change at run-time.

关于c - 错误 : variably modified 'd' at file scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21672639/

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