1. 初始化列表方案
定义变量时,使用大括号,如:
int a{2};
2. 引用(为现有变量提供别名)
int a=10;
int =b=3;
int &c=a;
C等于a,并不是单独为C开一个空格,而是使用一个引用方法,这样C和a被称为不同的名字,但实际上它们是完全相同的
3. Write interchange functions with references
//利用引用交换两个数
void swap(int& x, int& y) {int t = x;x = y;y = t;
}
4. Write swap functions using citations
References must reference variables that have already been defined, but frequent references can directly define values such as:
const int &x=100;
Bottom layer: const int *p=tmp;
tmp=100;
int & const q=x ----->等于 int & q=x
___________________________________________________________________________
4.左值与右值
左值:可以取地址
右值:不可以取地址
int a=4;
int &b=a;(左值,只有一个&)
int &&c=5;(右值,有两个&&)