题目:
#include
using namespace std;
{
return a[i];
}
int main()
{
int a[] = {1,2,3};
getElement(a,1) = 10;
cout << a[1] ;
return 0;
}
答案:int&
通过函数返回引用这种机制,可以对函数进行赋值,将函数放在赋值语句的左边。
不加&会报错,不能用getElement(a,1)=10这样的语法。
题目:
#include
using namespace std;
{
return a[i];
}
int main()
{
int a[] = {1,2,3};
getElement(a,1) = 10;
cout << a[1] ;
return 0;
}
答案:int&
通过函数返回引用这种机制,可以对函数进行赋值,将函数放在赋值语句的左边。
不加&会报错,不能用getElement(a,1)=10这样的语法。