一维数组传参
存放数组指针的数组
传参时形参的写法
一维数组
指针数组
二级指针存放一级指针地址,数组指针存放数组地址。
#include <stdio.h>
void test(int arr[])//ok
{}
void test(int arr[10])//ok
{}
void test(int *arr)//ok
{}
void test2(int *arr2[20])//ok
{}
void test2(int **arr2)//ok
{}
int main()
{
int arr[10] = {0};
int *arr2[20] = {0};
test(arr);
test2(arr2);
}
二维数组
二级指针只能存放一级指针的地址
数组指针是用来存放数组地址的。
void test(int arr[3][5])//ok
{}
void test(int arr[][5])//ok
{}
void test(int (*arr)[5])//ok
{}
int main()
{
int arr[3][5] = {0};
test(arr);
}
数组指针与指针数组传参易混淆点
指针数组能够用二级指针来获取,因为他的类型是int *
(虽然他是数组但是传参时可以用二级指针)
数组指针只能用数组指针来获取(要注意实参是 &数组名 还是 数组名)
共同点:都可以用他们本身做为参数。