#include
#include
using namespace std;
struct Student
{
string name;
int age;
int score;
};
//将函数中的形参改为指针,可以减少内存空间,而且不会复制新的副本出来
void prinarr(const Student *p)
{
//p->score = 80;//形参加了const修饰之后,一旦有修改的操作就会报错,以防止我们的误操作
cout << “姓名:” << p->name << “年龄:” << p->age << “分数:” << p->score << endl;
}
int main()
{
//创建结构体变量
Student s1 = { “张美丽”,16,90 };
prinarr(&s1);
system(“pause”);
return 0;
}
运行效果:
黑马程序员匠心之作|C++教程从0到1入门编程--练习-结构体中const的使用

相关文章:

  • 2021-04-07
  • 2021-11-17
  • 2021-09-15
  • 2021-05-28
  • 2021-04-21
  • 2021-08-01
  • 2022-12-23
  • 2021-09-01
猜你喜欢
  • 2021-11-07
  • 2021-11-18
  • 2021-11-21
  • 2021-04-21
  • 2021-08-22
  • 2021-12-28
  • 2022-12-23
相关资源
相似解决方案