Passing 2D Array of Pointers in C

后端 未结 4 1941
忘了有多久
忘了有多久 2021-01-23 09:47

For my program I need to pass a 2D array of pointers to a function in a separate file. I\'ve written a similarly-syntaxed file below:

#include 
#         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-23 10:35

    To achieve something similar to what you are trying C99 has variable length arrays. These come particularly handy in function definitions:

    void setFirst(size_t n, size_t m, card_t *cards[n][m]) {
    ...
    }
    

    Observe that you have to have the size parameters known at the moment of the array declaration, so you'd have to put them in front.

提交回复
热议问题