我想將2D數組傳遞給函數。我嘗試了互聯網上提供的不同解決方案。陣列差異之間的區別
int arr[3][4];
fun (arr);
1) void fun(int *a[4]) {} -- result into a compilation error (cannot convert int (*)[4] to int **)
2) void fun(int(*a)[4]) {} -- works fine.
我想知道上述兩個聲明之間的區別是什麼以及1. case中有什麼錯誤。
請編輯您的代碼,這既不是C也不是C++! – 2013-03-06 15:56:23
'int arr [3] [4]'會退化爲int *',而不是'int **'! – 2013-03-06 15:58:25
其中的一個需要一個「int」指針數組(大小在衰減期間丟失),另一個指針指向一個包含四個值的int數組。他們是完全不同的野獸。 – WhozCraig 2013-03-06 15:58:35