美文网首页
2.引用的注意事项

2.引用的注意事项

作者: lxr_ | 来源:发表于2021-01-14 11:17 被阅读0次
    #include<iostream>
    using namespace std;
    int main()
    {
        int a = 0;
        int d = 1;
    
        //注意:
        //1.引用必须要初始化
        //int& b;//出错
        //2.引用一旦初始化,就不可以更改
    
        int& c = a;
        c = d;//赋值操作,而不是更改引用
        cout << "a=" << a << endl;
        cout << "c=" << c << endl;
        cout << "d=" << d << endl;
    
        system("pause");
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:2.引用的注意事项

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