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

前端 未结 5 642
旧时难觅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 01:57

    I don't know what you mean by "data dont get lost". Here's how you pass a normal 2D array to a function:

    void myfunc(int arr[M][N]) { // M is optional, but N is required
      ..
    }
    
    int main() {
      int somearr[M][N];
      ...
      myfunc(somearr);
      ...
    }
    

提交回复
热议问题