Array length problem

后端 未结 6 1569
栀梦
栀梦 2021-01-21 07:46

I was reading a csc placement paper where I read a question related to c language array\'s sizeof() operator. Answer was something else then i expected it to be.



        
6条回答
  •  粉色の甜心
    2021-01-21 08:23

    See the syntax for the function defination can be written following way

     int DIMension(int array[]) {
     return sizeof(array )/ sizeof(int);
     }
    
    
     int DIMension(int *array) 
     {
     return sizeof(array )/ sizeof(int);
     }
    
    int DIMension(int array[10])
    {
    return sizeof(array )/ sizeof(int);
    }
    

    All these three statement has same meaning and common thing across the three is the argument array which is nothing but a pointer to array which is always gonna to be 4 bytes

提交回复
热议问题