推荐使用引用的方式。因为传递的是变量的地址,因而效率较高,并且可读性也高
#include <iostream>
#include <string>
using namespace std;
struct Student
{
int num;
string name;
float score[3];
}stu={12345,"Li Li",67.5,89,78.5};
void print(Student &stud)//函数定义,形参为结构体Student变量的引用
{
cout<<stud.num<<" "<<stud.name<<" "<<stud.score[0]
<<" " <<stud.score[1]<<" "<<stud.score[2]<<endl;
}
int main( )
{
print(stu);//实参为结构体Student变量
return 0;
}
另外还有两种方法但缺点都比较明显