这里先记一点,数组在作为参数传递的时候,传入的只是它的首地址,通过下面的程序来理解一下:
#include <stdio.h>
void change(int a[])
{
printf("the size of array in change function is %d\n",sizeof(a));
}
int main(void)
{
int a[]={1,2,3};
change(a);
printf("the size of array in main function is %d",sizeof(a));
}
/********************************************/
输出的为:
the size of array in change function is 4
the size of array in main function is 12
/********************************************/
再贴一段代码:
int main(void)
{
int a = 101;
int c=102;
int b[3];
b[-1]=0;
b[0]=1;
b[1]=2;
b[2]=3;
b[3]=4;
printf("a is %d\n",a);
printf("c is %d\n",c);
printf("b-&a=%d\n",b-&a);
printf("&c-&a=%d",&c-&a);
}
/********************************************/
输出结果是:
a is 4;
c is 0;
b-&a=-3;
&c-&a=-4;
/********************************************/