我想將使用malloc定義的2d數組傳遞給函數。 首先我使用blog post的代碼定義數組。如何使用malloc定義2d數組並將其傳遞給函數
int** Make2DIntArray(int arraySizeX, int arraySizeY) {
int** theArray;
theArray = (int**) malloc(arraySizeX*sizeof(int*));
for (int i = 0; i < arraySizeX; i++)
theArray[i] = (int*) malloc(arraySizeY*sizeof(int));
return theArray;
}
int main(){
int** myArray = Make2DIntArray(nx, ny);
}
我可以用它作爲myArray [i] [j]。 在那之後,我想通過這個數組的function.I試圖通過這樣的:
function(myArray); //function call
//function
void function(int myArray[][]){
//function code goes here
}
但這wrong.The問題是,數組的大小是不同的每再寄一次也試圖定義的最大尺寸爲陣列的列,並使用它是這樣的:
#define COLUMNMAX 100
function(myArray); //function call
//function
void function(int myArray[][COLUMNMAX]){
//function code goes here
}
,但我得到了錯誤:
type of formal parameter 1 is incomplete.How can i pass it?
[閱讀](http://c-faq.com/aryptr/aryptr2.html) – 2013-06-21 13:16:21