我有几个简单的问题:-
根据普通的 C++ 编译器,以下内容正确吗?
int arr[3][4];
void func(int *a, int m, int n)
{
int i,j;
cin>>i>>j;
cout<< a[i*n + j]; //is this way of addressing correct provided 0<=i<m and 0<=j<n
}
int main()
{
func((int*)arr, 3,4);
}
如果数组的边界严格必须是常量表达式,为什么下面的代码不会生成编译器错误?
int func(int m, int n)
{
int arr[m][n]; //m and n are not known until run time
}