Miscalculation of array size inside a function

前端 未结 3 1749
小鲜肉
小鲜肉 2020-12-12 06:04

The following C program:

int doStuff(int afm[]);

int main(){
    int afm1[9] = {1,2,3,4,5,6,7,8,9}; //size=9

    int afmLength = sizeof(afm1)/sizeof(int);
         


        
3条回答
  •  无人及你
    2020-12-12 06:57

    Because in main you have an array and in the function you have a pointer to that array.

    int doStuff(int afm[])
    

    is equivalent to

    int doStuff(int *afm)
    

提交回复
热议问题