sizeof(arr)
#include<stdio.h>
void Func(char str_arg[100])
{
printf("%d\n",sizeof(str_arg)); // 4
}
int main(void)
{
char str[]="Hello";
printf("%d\n",sizeof(str));//6
printf("%d\n",strlen(str));// 5
char*p=str;
printf("%d\n",sizeof(p));// 4
Func(str);
}
- 数组作为函数参数传递
数组有两个特殊的性质。一是不能复制数组;
二是使用数组名字时,数组会自动转化为指向其第一个元素的指针。
由于数组不能复制,所以无法编写使用数组类型形参的函数,因为数组会被自动转化为指针。