在C語言中末患,數(shù)組作為函數(shù)參數(shù)時(shí)將退化為指針瞒津。
#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;
}