美文网首页
2.结构体作函数参数.cpp

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

作者: lxr_ | 来源:发表于2020-12-26 20:07 被阅读0次

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

    }

    相关文章

      网友评论

          本文标题:2.结构体作函数参数.cpp

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