引用参数理解
1.值传递
main 方法:
int main(){ int dev=333; int &ReNameDev=dev; cout<<"输出:dev="<<dev<<"\n"; cout<<"输出:ReNameDev="<<ReNameDev<<"\n"; ReNameDev=999; cout<<"直接修改引用值以后:dev="<<dev<<"\n"; cout<<"直接修改引用值以后:ReNameDev="<<ReNameDev<<"\n"; Modify(ReNameDev); cout<<"Modify(ReNameDev)->dev="<<dev<<"\n"; cout<<"Modify(ReNameDev)->ReNameDev="<<ReNameDev<<"\n"; }
void Modify(int item):
void Modify(int item){ item=100000; }
执行结果:
2.引用地址?
当方法Modify 修改为:
//引用参数 void Modify(int& item){ item=100000; }
输出结果: