结论
数组传参本质上传递的是地址。
一维数组传参
先看主函数
int main()
{
int arr1[5] = { 0 };
int* arr2[10] = { 0 };
test1(arr1);
test2(arr2);
return 0;
}
test1() 函数可以这么设计
void test1(int arr[5])
{ }
void test1(int arr[ ])
{ }
void test1(int* arr)
{ }
这三种方式都是可以的。数组传参本质上是地址,数组本质上是指针,所以用指针接收地址是正确的。(形参数组方括号[ ]中的数字可有可无,编译器是不读的)
同理,test2() 函数可以这么设计
void test2(int* arr[10])
{ }
void test2(int** arr)
{ }
二维数组传参
先看主函数
int main()
{
int arr[3][4] = { 0 };
test(arr);
return 0;
}
下面判断 test() 函数设计是否正确
void test(int arr[3][