2.结构体作函数参数.cpp

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

#include<iostream>

using namespace std;

struct  student

{

    string name;

    int age;

    int score;

};

void print1(student s)

{

    cout << "姓名:" << s.name << "  " << "年龄:" << s.age     << "  " << "分数:" << s.score << endl;

}

void print2(student* s)

{

    cout << "姓名:" << s->name << "  " << "年龄:" <<     s-       >age << "  " << "分数:" << s->score << endl;

}

int main()

{

    student s = {"xiansifan",22,90 };

    cout << s.name << "  " << s.age << "  " << s.score << endl;

    //print1(s);

    print2(&s);

    system("pause");

    return 0;

}

上一篇下一篇

猜你喜欢

热点阅读