我有幾個簡單的問題: -陣列申報和解決
是按照正常的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 }
根據嚴格的標準閱讀,通常不可能像使用平面數組一樣使用多維數組(超出前幾個元素)。然而,這是經常被忽略的事情,因爲我沒有真正找到任何答案提到它 - 除了[one](http://stackoverflow.com/a/7273599/726300) 。 –