注意:不想修改主函数中的数据用值传递,否则用地址传递 #include #include using namespace std; struct Student { string name; int age; int score; }; //1、值传递 void prin01(Student p1) { p1.age = 35; p1.score = 60; cout << “pin01函数内学生的姓名:” << p1.name << “年龄:” << p1.age << “分数:” <<p1.score << endl; } //2、地址传递 void prin02(Student *p2) { p2->age = 20; p2->score = 90; cout << “pin02函数内学生的姓名:” <name << “年龄:” << p2->age << “分数:” << p2->score << endl; } int main() { struct Student s1; s1.name = “张美丽”; s1.age = 18; s1.score = 100; prin01(s1); cout << “调用pin01之后学生的姓名:” << s1.name << “年龄:” <<s1.age<<“分数:”<< s1.score << endl; prin02(&s1); cout << “调用pin02之后学生的姓名:” << s1.name << “年龄:” << s1.age << “分数:” << s1.score << endl; system(“pause”); return 0; } 运行结果为: