美文网首页
3.结构体中使用const

3.结构体中使用const

作者: lxr_ | 来源:发表于2020-12-29 13:41 被阅读0次

#include<iostream>

using namespace std;

struct student

{

    string name;

    int age;

    int score;

};

void print(const student* s)//地址传递可改变实参

{

    //s->age = 100;const不可修改,防止误操作

    cout << s->name << "  " << s->age << "  " << s->score <<     endl;

}

int main()

{

    student s = { "xian",34,55 };

    print(&s);

    system("pause");

    return 0;

}

相关文章

网友评论

      本文标题:3.结构体中使用const

      本文链接:https://www.haomeiwen.com/subject/ymognktx.html