c++:同样是数组下标,为啥定义数组时必须是常量表达式,而在赋值过程中就可以用int
#include<iostream>using std::cout;
using std::endl;
int main()
{
constexpr int m = 3, n = 4;
int a[m][n];
for (size_t i = 0; i < m; ++i) //就是这里呀
{
for (size_t j = 0; j < n; ++j) //还有这里,虽然书上是size_t,但是用int定义也没问题,求解。。
{
a[i][j] = 4 * i + j;
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}