数组作为参数传递的时候,被调用的函数内无法计算出数组的大小

 
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 int ff (int c[])//被调用的函数
 4 {
 5     int e;
 6     e = sizeof (c) ;
 7     return e;
 8 }
 9 int main(void) { 
10     
11    int c[7] = {1,2,3,6,2,2,7};
12    
13     int e,k;
14     e = sizeof (c);
15     
16     k = ff(c);
17     printf("%d###%d",e,k);//执行结果,28###8
18         
19     return 0;
20 }

在main函数中,sizeof可以计算出数组真实的所占内存大小。但是调用ff函数时候,ff函数只把实际参数当成一个指针来看待,并不清楚他是一个需要占用多大内存

图片截取自现代方法第九章第3节

原文地址:https://www.cnblogs.com/saolv/p/7506173.html