3.结构体中使用const

2020-12-29  本文已影响0人  lxr_

#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;

}

上一篇 下一篇

猜你喜欢

热点阅读