一維數組合、二維數組引用的方式類似,直接看代碼就好。
#include<iostream>
using namespace std;
int main()
{
//一維數組
int m[4] = { 1, 2, 3, 4 };
int(&a)[4](m);
for (int i = 0; i<4; i++)
{
cout << m[i] << " ";
a[i] += 1;
}
cout << endl;
for (int i = 0; i<4; i++)
{
cout << m[i] << " ";
}
cout << endl;
//二維數組
int mm[2][2] = { { 1, 2 }, { 3, 4 } };
int(&aa)[2][2](mm);
cout << mm[0][0] << endl;
aa[0][0] += 1;
cout << mm[0][0] << endl;
system("pause");
return 0;
}
運行結果如圖: