const变量的修改实践

Posted do-your-best

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了const变量的修改实践相关的知识,希望对你有一定的参考价值。

https://bbs.csdn.net/topics/110049293

#include <iostream>

using namespace std;

int main()

    cout << "const变量实践:" << endl;


    // 必须加 volatile才会改变
    const volatile int a111 = 1;

    *((int*)&a111) = 22222;
    cout<<a111<< endl;;

    cout << "a111:" << a111 << endl;

    register int b = 2;

    cout << "b:" << b << endl;

    int *p1 = (int*)&a111;
    cout << "*p11:" << *p1 << endl;

    int *p2 = &b;
    cout << "*p2:" << *p2 << endl;

    cout << "end." << endl;
    return 0;

技术图片

 

以上是关于const变量的修改实践的主要内容,如果未能解决你的问题,请参考以下文章

const详解

Flutter 最佳实践 - 04

c++const定义的变量可以改变吗

C语言如何修改const结构体内的变量

使用二级指针修改带const的只读变量

C++中如何可以修改const函数内的成员变量的值?