1、方法一 :利用指针传递
#include<iostream>
using namespace std;
void sub(int *arr )
{
arr[1] = 43;
}
int main()
{
int arr[2] = { 1,2 };
sub(arr);
cout << "arr[1]=" << arr[1] << endl;
system("pause");
return 0;
}
2、方法二:传递数组的首地址
#include<iostream>
#include<typeinfo>
#include<vector>
#include<algorithm>
using namespace std;
void sub(int arr[])
{
arr[0] = 10;
}
int main()
{
int arr[10] = { 1,2 };
cout << "arr[0]=" << arr[0] << endl;
sub(arr);
cout << "arr[0]=" << arr[0] << endl;
system("pause");
return 0;
}