#include <iostream> #include <vector> #include <algorithm> #include<array> using namespace std; int main() { int a=20; int &b=a; cout<<"a="<<a<<endl; cout<<"b="<<b<<endl; a=a+5; cout<<"a="<<a<<endl; cout<<"b="<<b<<endl; b=b+5; cout<<"a="<<a<<endl; cout<<"b="<<b<<endl; }
输出结果:
F:\untitled\cmake-build-debug\untitled.exe
a=20
b=20
a=25
b=25
a=30
b=30
进程已结束,退出代码为 0
从结果来看,变量a和变量b是等价的