在C语言中,数组作为函数参数时将退化为指针。
#include <stdio.h>
//Sizeof on array function parameter will return size of 'int *' instead of 'int []'
int sizeofArray(int array[]){
return sizeof(array);
}
int main(int argc, const char * argv[]) {
// insert code here...
int data1[] = {1, 2, 3, 4, 5};
size_t size1 = sizeof(data1);
int *data2 = data1;
size_t size2 = sizeof(data2);
size_t size3 = sizeofArray(data1);
printf("%zd, %zd, %zd\n", size1, size2, size3);
return 0;
}