C++ 基础 const

文章目录

const 修饰

const int * t 和 int const * t是等价的

因此可以看出const 是对前生效。

#include <iostream>

using namespace std;

int main()
{
        int mt = 122;
        int nt = 124;
        int tt = 123;
        const int * tmnp = &tt;
        int const * mcnt = &mt;
        int * const ncmt = &nt;
        *tmnp = 123;
        //*mcnt = 123;
        mcnt = &nt;
        tmnp = &nt;
        //ncmt = &mt;
        cout <<*mcnt<<endl;
        cout <<*ncmt<<endl;
        return 0;
}

猜你喜欢

转载自blog.csdn.net/LHshooter/article/details/87871944