C++-结构体做函数参数

#include 
using namespace std;

struct student {
	string name;
	int age;
	int score;
};

//函数
//1.值传递
void printStu1(struct student h) {
	cout << "姓名:" << h.name << "年龄:" << h.age << "分数:" << h.score << endl;
}
//2.地址传递
void printStu2(struct student* h) {
	cout << "姓名:" << h->name << "年龄:" << h->age << "分数:" << h->score << endl;
}

int main() {
	
	struct student s;
	s.name = "王五";
	s.age = 18;
	s.score = 99;
	printStu1(s);
	printStu2(&s);
	system("pause");
	return 0;
}

你可能感兴趣的:(C++,c++,开发语言,算法)