8.7结构体中const用法
#include <iostream>
using namespace std;
#include <string>
struct student
{
string name;
int age;
int score;
};
void printstudent(const student *s)
{
cout << s->age << endl;
}
int main8_7()
{
struct student s = { "aaa", 15, 70 };
printstudent(&s);
system("pause");
return 0;
}
8.6结构体做函数参数
#include <iostream>
using namespace std;
#include <string>
struct student
{
string name;
int age;
int score;
};
void printst(struct student ss)
{
cout << "值"<<ss.name << endl;
}
void printst2(struct student *p)
{
cout << p->age;
}
int main8_6()
{
struct student s;
s.age = 44;
s.name = "sss";
s.score = 88;
printst(s);
printst2(&s);
system("pause");
return 0;
}