Pass 2d array to function in C?

后端 未结 3 1523
半阙折子戏
半阙折子戏 2021-01-22 14:28

I know it\'s simple, but I can\'t seem to make this work.

My function is like so:

 int GefMain(int array[][5])
 {
      //do stuff
      return 1;
 }
         


        
3条回答
  •  独厮守ぢ
    2021-01-22 15:25

    The code is fine. In a single file, this compiles fine for me with gcc.

    int g(int arr[][5])
    {
        return 1;
    }
    
    int main()
    {
        int array[1800][5];
        g(array);
        return 0;
    }
    

    My guess is that you're #includeing the wrong file -- perhaps one that had a different declaration for GefMain. Or perhaps you just haven't saved the file that declared GefMain, so it still has an argument of int [][3], for instance, which would cause the warning.

    I would suggest that you post the entire code to reproduce the problem (after you strip out everything that's unneeded to reproduce it, of course). But chances are, at that point, you'll have solved it yourself.

提交回复
热议问题