代码 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 2
而 Code 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/