数组地址传递和值传递区别在哪里?都能修改的话;是不是随便自己选择?
#include<iostream>
using namespace std;
struct hero {
string name;
};
void test01(hero *a) { //地址传递
a->name = "王五";
cout << "test01\t函数中:" << a->name << endl;
}
void test02(hero b[]) {//值传递
b[0].name = "阿花";
cout << "test02\t函数中:" << b[0].name << endl;
}
int main(){
hero a[] = {"张三"};
test01(&a[0]);
cout << "test01\tmain函数中" << a[0].name << endl;
hero b[] = { "李四" };
test02(b);
cout << "test02\tmain函数中" << b[0].name << endl;
system("pause");
return 0;
}