Miscalculation of array size inside a function

前端 未结 3 1745
小鲜肉
小鲜肉 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:49

    Adding to David Heffernan's answer (which is correct), you should have another parameter which would be the array length passed onto your doStuff method.

提交回复
热议问题