C++ 左值表达式
左值表达式可以是变量,指针和引用,所以函数的返回值是这些类型,也能用在赋值号左边。
#include <iostream>
using namespace std;
int x = 10;
int y = 20;
int & refValue(int & x){
return x;
}
int main(){
cout << "leftValue before \tx: " << x << '\n';
refValue(x) = 30;
cout << "leftValue after \tx: " << x << '\n';
cout << "-------------------------------\n";
cout << "leftValue before \ty: " << y << '\n';
refValue(y) = 40;
cout << "leftValue after \ty: " << y << '\n';
return 0;
}


浙公网安备 33010602011771号