8.7结构体中const用法

# 8.7结构体中const用法

#include 
using namespace std;
#include 
struct student
{
	string name;
	int age;
	int score;
};
//将函数中形参改为指针可以减少内存空间,
//不会复制一个新的副本
void printstudent(const student *s)
{
	//s->score = 444;加const后,就不能在修改了!!
	cout << s->age << endl;
}
int main8_7()
{
	struct  student s = { "aaa", 15, 70 };
	printstudent(&s);
	system("pause");
	return 0;
}

# 8.6结构体做函数参数

#include 
using namespace std;
#include 
struct student
{
	string name;
	int age;
	int score;
};
//值传递方法
void printst(struct student ss)
{
	cout << "值"<age;
}
int main8_6()
{
	struct student s;
	s.age = 44;
	s.name = "sss";
	s.score = 88;
	printst(s);
	printst2(&s);

	//cout << "main" << s.name << endl;
	system("pause");
	return 0;
}

你可能感兴趣的:(蓝桥杯,c++,散列表)