C语言学习打卡2021.11.24(指针进阶3)

c语言编程 C语言入门 c语言(C语言程序设计教程 c语言视频教程 c语言零基础入门教程 学习c语言 c语言视频教程 c语音 C语言教程 C语言编程项目 C语言_哔哩哔哩_bilibili学习C语言学习C语言程序设计教程 c语言视频教程 谭浩强 c语言学习 谭浩强 谭浩强c语言零基础入门教程 c语言 c语言视频教程 c语音 C语言教程 C语言编程项目 C语言学习C语言程序设计教程 c语言视频教程 c语言零基础入门教程 c语言 c语言视频教程 c语音 C语言教程 C语言编程项目 C语言学习 C语言 c语言 C语言程序设计https://www.bilibili.com/video/BV1q54y1q79w?我的github主页

remeke (remeke) · GitHuba student. remeke has one repository available. Follow their code on GitHub.https://github.com/remeke

数组参数、指针参数

在写代码的时候难免要把【数组】或【指针】传给函数,那函数的参数该如何设计呢?

一维数组的传参

#include<stdio.h>
/*void test(int arr[])
{
	
}
void test(int arr[10])
{
	
}
void test(int*arr)
{
	
}
void test2(int*arr[20])
{
	
}
void test2(int**arr)
{
	
}*/
//以上写法都成立 
int main()
{
	int arr[10]={0};
	int *arr2[20]={0};
	test(arr);
	test2(arr2);
	return 0;
}

二维数组的传参

#include<stdio.h>
void test(int arr[3][5])
{
	
}
void test1(int arr[][5])
{
	
}
//void test2(int arr[3][])//err
//void test1(int arr[][])//err

int main()
{
	int arr[3][5]={0};
	test(arr);//二维数组传参 
	test1(arr);
	test2(arr);
}

注意二维数组的传参只能省略行,不能省略列。

函数指针-指向函数的指针-存放函数地址的一个指针

#include<stdio.h>
int Add(int x,int y)
{
	int z=0;
	z=x+y;
	return z; 
}
int main()
{
	int a=10;
	int b=20;
	printf("%d\n",Add(a,b));
	printf("%p\n",&Add);
	printf("%p\n",Add);
	//&函数名和函数名都是函数的地址
	int(*pa)(int,int)=Add;
	printf("%d\n",(*pa)(2,3));
	return 0;
}

 两段有趣的代码:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值