c++ day2

#include <iostream>

using namespace std;
/*void row(int &p,int &q)//引用
{
    int t;
    t=p;
    p=q;
    q=t;
}*/
/*struct ab
{
    string name;
   // int &age;
};
void add(int a,int b)
{
    cout << a+b<< endl;
}
void add(float a,float b)
{
    cout << a+b << endl;
}
void add(string a, string b)
{
    cout << a+b <<endl;
}*/
struct stu
{
    string xingbie;
    int nl;
    void fun();
    void set_get(string a,int b)
    {
        name=a;
        chengji=b;
    }
private:
    string name;
    int chengji;
};
void stu::fun()
{
    cout << name << endl;
    cout << chengji << endl;
    cout << nl << endl;
    cout << xingbie << endl;
}
int main()
{
    /*int a=100,b=200;
    int &re=a;
    int &rd=b;
    row(re,rd);
    cout <<"&a"<< &a << endl;
    cout <<"&re" << &re <<  endl;
    cout <<"&rd" << &rd << endl;
    cout <<"re=" << re <<endl;
    cout <<"a="<<a<<endl;
    cout <<"b="<<b<<endl;*/
    /*int t;
    int a[5]={1,4,3,2,5};
    int (&re)[5]=a;
    int b=10;
    int *p=&b;
    int &rd=p;*/
  /*  int x=18;
  struct ab a={"zhangsan",x};
    struct ab a;
    a.name="zhangsan";
    cout << a.name << endl;*/

    /*
    int *p=new int ;
    cout <<"p="<< p<< endl;

    int *q=new int [5]{1,2,3,4,5};
    for(int i=0;i<5;i++)
    {
        cout << q[i] << endl;
    }*/
    /*int a=1;
    int b=2;

    float c=1;
    float d=2;

    string e="hello";
    string f="world";
    add(a,b);
    add(c,d);
    add(e,f);*/
    struct stu s1;
    s1.set_get("zhangsan",100);
    s1.nl=18;
    s1.xingbie="男";
    s1.fun();












    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值