C pointer notation compared to array notation: When passing to function

后端 未结 6 880
野的像风
野的像风 2020-12-01 18:52

My question is base on the following code:

int myfunct(int ary[], int arysize)   
int myfunct2(int *ary, int arysize)

 int main(void){
   int numary[10];
         


        
6条回答
  •  一整个雨季
    2020-12-01 19:20

    In my opinion, the main reason to prefer pointer notation over empty array notation in function prototypes is that the latter is not consistent with structure definitions:

    struct person {
       char *firstname;
       char *lastname;
    };
    
    void setperson(struct person *p, char firstname[], char lastname[])
    {
        p->firstname = firstname;
        p->lastname = lastname;
    }
    

    In structures you will have to use the pointer notation anyway because empty array notation is only valid, at least since C99, for the last member when you want to make it a flexible array member.

提交回复
热议问题