数组的引用

#include 
using namespace std;

void test(int(&array)[2])		//此处必须指定个数,否则编译不通过 
//void test(int array[])
{
	for (int i = 0; i < 2; i++)
		array[i] = array[i] * 2;
}


int main()
{
	int brr[3] = { 2,5,6 };
	int(&temp)[3] = brr;		//数组的引用 

	char c[6] = "Hello";
	char(&rc)[6] = c;			//数组的引用 

	for (int i = 0; i < 3; i++)
		cout << brr[i] << " ";	cout << endl;

	for (int i = 0; i < 3; i++)
		cout << temp[i] << " ";  cout << endl;

	cout << c << endl;
	cout << rc << endl;

	int Arr[2] = { 3,5 };
	test(Arr);
	for (int i = 0; i < 2; i++)
		cout << Arr[i] << "  ";
	cout << endl;
	return 0;
}

数组的引用_第1张图片

你可能感兴趣的:(C++,c++)