使用引用返回函数值
#include <iostream>
using namespace std;
int a[]={1,3,5,7,9};
int &index(int i){
return a[2];
}
int main(){
cout<<index(2)<<endl;
cout<<a[2]<<endl;
index(2)=25;
cout<<a[2]<<endl;
cout<<index(2);
return 0;
using namespace std;
int a[]={1,3,5,7,9};
int &index(int i){
return a[2];
}
int main(){
cout<<index(2)<<endl;
cout<<a[2]<<endl;
index(2)=25;
cout<<a[2]<<endl;
cout<<index(2);
return 0;
}
结果:
5
5
25
25