有些书上说,不能建立数组的引用,鄙人不敢苟同。
int a= 10;
int *p = &a;
int &b = a;
我发现引用的建立就是把int * p = & a中&和*互相调换,那么数组中是否也可以呢
#include<iostream>
using namespace std;
int main()
{
int arr[3]={1,2,3};
//int (*p)[3] = &arr;
int (&p)[3] = arr;//一维数组
cout<<p[0]<<endl;
cout<<p[1]<<endl;
cout<<p[2]<<endl;
cout<<"######################"<<endl;
int brr[2][3] = {1,2,3,4,5,6};
//int ((*s)[2])[3] = &brr;
int ((&s)[2])[3] = brr;//二维数组
cout<<s[0][0]<<endl;
cout<<s[0][1]<<endl;
cout<<s[0][2]<<endl;
cout<<s[1][0]<<endl;
cout<<s[1][1]<<endl;
cout<<s[1][2]<<endl;
return 0;
}
以上代码,运行正常,所以,我认为,能建立引用数组,请多多指教