目录
1.引用
2.引用做函数参数
3. //引用作函数的返回值
//1.不要返回局部变量的引用
//2.函数调用作为函数的左值
4.引用的本质
//reference
//pointer
5.常量引用-常量的引用
//1.
//const
//2.函数形参 const 与 非 const
1.引用
int a=10;
int b=20;
//int &c; //需要初始化
int &c=a;//不能更改
c=b; //赋值操作 非更改引用
//&c=b; //不能更改
cout<
cout<
cout< // int &&d=b; //不存在引用的引用 int *p=&a; int *&e=p; //指针的引用 // int &*f=&b; //不存在引用的指针 void swap(int& a,int& b); int _tmain(int argc, _TCHAR* argv[]) { int a=10; int b=20; swap(a,b); cout<<"a="<
//引用作函数参数 return 0; } void swap(int& a,int& b) { int temp; temp=b; b=a; a=temp; } // int & fun() { int a=10;//局部变量存放在栈区 return a; } int _tmain(int argc, _TCHAR* argv[]) { int &b=fun(); cout<
cout<
return 0; } int & fun() { static int a=4;//静态变量 在全局区 可以返回 return a; } int _tmain(int argc, _TCHAR* argv[]) { int &ref=fun(); cout<
cout<
fun()=1000;// 函数的返回值为引用 函数调用可以作为左值; cout<
2.引用做函数参数
3. //引用作函数的返回值
//1.不要返回局部变量的引用
//2.函数调用作为函数的左值



