一维数组传参(一维数组作函数参数)

  • 一维数组进行传参的时,函数参数可以写成数组或指针(因为数组名是地址,可用指针接收);

其中参数是数组时,数组大小可写也可不写;

参数是指针时要找到对应的指针类型才行;

  • 传递参数是普通数组  arr(3种方式):
#include<iostream>
using namespace std;
void test(int arr[]) {

}
void test(int arr[10]) {

}
void test(int* arr) {

}
int main() {
	int arr[10] = { 0 };
	test(arr);
	system("pause");
	return 0;
}
  •    传递参数是指针数组  arr2(3种方式):     

一级指针的地址可以用二级指针接收;对于数组 arr2,数组名是首元素地址,数组每个元素是int*,也就是说数组名是一个一级指针的地址,传入参数是数组名,那么就可用一个二级指针接收:int **arr

#include<iostream>
using namespace std;
void test(int* arr[20]) {

}
void test(int* arr[]) {

}
void test(int **arr) {

}
int main() {
	int* arr2[20] = { 0 };
	test(arr2); //数组名是首元素地址
	system("pause");
	return 0;
}

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值