How to pass 2D array (matrix) in a function in C?

前端 未结 5 704
旧时难觅i
旧时难觅i 2020-11-22 01:31

I need to do this to persist operations on the matrix as well. Does that mean that it needs to be passed by reference?

Will this suffice?

void operate

5条回答
  •  眼角桃花
    2020-11-22 02:03

    Easiest Way in Passing A Variable-Length 2D Array

    Most clean technique for both C & C++ is: pass 2D array like a 1D array, then use as 2D inside the function.

    #include 
    
    void func(int row, int col, int* matrix){
        int i, j;
        for(i=0; i

    Internally, no matter how many dimensions an array has, C/C++ always maintains a 1D array. And so, we can pass any multi-dimensional array like this.

提交回复
热议问题