Passing a 2d dynamic array to a function in C++

前端 未结 5 1505
长情又很酷
长情又很酷 2021-01-19 23:52

I have this 2d dynamic array and I want to pass it to a function, How would I go about doing that

int ** board;
        board = new int*[boardsize];

                


        
5条回答
  •  一生所求
    2021-01-20 00:44

    int **board; 
    board = new int*[boardsize]; 
    
    for (int i = 0; i < boardsize; i++)
        board[i] = new int[size];
    

    You need to allocate the second depth of array.

    To pass this 2D array to a function implement it like:

    fun1(int **);
    

    Check the 2D array implementation on below link:

    http://www.codeproject.com/Articles/21909/Introduction-to-dynamic-two-dimensional-arrays-in

提交回复
热议问题