【发布时间】:2019-04-11 22:30:25
【问题描述】:
我正在尝试将数组用作全局变量。似乎我不能使用先前初始化的变量(例如 l)来确定数组的尺寸,并且出现以下错误
错误:数组绑定在 ']' 标记之前不是整数常量。
但是,当我尝试在 main 函数中使用相同的东西时,这是可能的。
有人能解释一下这里发生了什么吗?
// If you move the following lines inside the main function then everything works fine
int l = 3;
int a[l] = {1, 2, 3};
int main()
{
return 0;
}
【问题讨论】:
标签: c++ arrays global-variables