C++ Primer Plus第七天

复习函数的基本知识

为了提高效率,可以学习学习,STL和boost

前提:
	提供函数原型:一般在头文件里写
	提供函数定义
	调用函数

函数参数的按值传递

void number (int a);

函数和数组

int sum(int a[],int size);
此时的数组参数不是副本,所以为了安全,加上const:
int sum(const int a[],int size);
补充:
	int *p
	const int *p:*p = 10 (NO) p= &a (OK)
	int * const p
	const int * const p;

函数和二维数组

int sum(int a[][4],int size);
补充:
	a[b][c] = *(*(a+b)+c);
			   =*(a+b)[c];

函数和C风格字符串

因为字符串有固定的结束符,所以可以不用加size;
int chars(char *p)

函数和结构

可以传值,可以传地址;

函数和string对象

多个字符串
void mypoint(string a [],int a)

函数与array对象

std::array<double,4>expenses;
按值:show(std::array<double,4> expenses);
地址:show(std::array<double,4> *expenses);

递归

调用自己~必须要给结束方式

函数指针

int (*p) (int a,int b);//函数指针
int (*p[3])(int ,int);
int * p (int a,int b);//指针函数

int (*p)(int,int) = fun1;
利用typedef 起别名:
	typedef int (*p)(int,int);
	p n1 = fun1;
	p n2[3];
	n2[0] = fun2;
	n2[1] = fun3;
	n2[2] = fun4;
补充:auto 可以让编译器自己辨别类型
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值