C++ Primer 5th笔记(6)chapter6 函数: 参数
生活随笔
收集整理的这篇文章主要介绍了
C++ Primer 5th笔记(6)chapter6 函数: 参数
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1 变量
1.1 自动对象:只存在于块执行期间的对象。
1.2 局部静态对象local static object
在程序的执行路径第一次经过对象定义语句时初始化,
程序终止结束
2.参数
2.1 指针形参
void reset(int *ip) {*ip = 0; // changes the value of the object to which ip pointsip = 0; // changes the local copy of ip; the argument is unchanged }2.2. const 形参
void reset(int &); const int ci; reset(ci);//error2.3. 数组引用形参
// returns a reference to an array of five int elements void f(int (&arr)[5] )2.4. 多维数组
void print(int (*ia)[10], size_t size); <=> void print(int ia[][10], size_t size);eg.
void main(int argc, char* argv[])2.5.可变形参
. initializer_list
void error_msg(initializer_list<string> il); void error_msg(ErrCode e, initializer_list<string> il);. 省略符形参…
void f(…);
3 返回值
3.1. 值是如何被返回的:临时量
3.2. 不能返回局部对象的引用或指针
3.3. 引用返回左值
3.4 列表初始化返回值
vector<string> f(){return {"1", "2"}; }3.5. main函数:编译器隐式插入return 0
3.6. 返回数组指针
eg.
int (*func(int i))[10]; auto func(int i) -> int (*)[10];//使用decltype int odd[] = {}; decltype(odd) *f(int i){return &odd; }总结
以上是生活随笔为你收集整理的C++ Primer 5th笔记(6)chapter6 函数: 参数的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: C++ Primer 5th笔记(5)c
- 下一篇: C++ Primer 5th笔记(6)c