Passing 2D Array of Pointers in C

后端 未结 4 1935
忘了有多久
忘了有多久 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

    Only the first index is optional. You should definitely mention the second index, because a two dimensional array decays to a pointer to 1d array.

    void setFirst(card_t *cards[][5]) {
                               // ^ Newly added
    
     // ..
    
    }
    

    Also make sure that the pointers are pointing to valid memory locations. Else dereferencing leads to segmentation faults. BTW, is there any reason to have a two dimensional array with pointers. I think you are just complicating the program.

提交回复
热议问题