今天遇到的问题:C++的语句
#include <iostream>
const int m = 1000, n = 1000;
int mat[m][n];
int main()
{
...
return 0;
}
转到C语言 报错:
error: variably modified ‘mat’ at file scope
C++中 const
修饰的变量为常量,存储在堆栈特殊的位置,所以可以正确使用const修饰的这个常量的值去开辟一个数组。
而在C中使用const
不能直接当成常量,const修饰的变量一般只当成“只读的”,而不是将其作为一个常量。所以如果在C中的全局声明一个数组,不能使用const变量做下标。