上问题
以前对引用的印象大概是这样:int &;
但是引用的是数组,那该怎么写呢?
在VS2022上试错若干遍,终于弄出来了。
唠嗑
1.假设被引用的数组是b[5]
实参是b,而不是b[5],b[5]只是个数字。
2.引用的写法 int (& c)[5]
区别在于括号
上代码
#include <iostream>
using namespace std;
void fun(int (& c)[5]) { cout<< c[0]; }
int main()
{
int a, b[5]={0,1,2,3,4};
int(& d)[5] = b;
cin >> d[0];
fun(b);
return 0;
}
运行界面
7
7