#include <iostream>
using namespace std;
#include<string>
//1、对const修饰的变量取地址的时候,会分配临时内存
void test01()
{
const int m_A = 10;
int* p = (int*)m_A;
}
//2、const前加入 extern关键字后,也会分配内存=> test.cpp看
//3、使用变量来初始化const修饰的变量
void test02()
{
int a = 10;
const int m_A = a; //但是如果m_A=10的话,无法修改
int* p = (int*)&m_A;
*p = 20;
cout << m_A << endl;
}
int main()
{
test03();
system("pause");
return 0;
}
C++核心编程 04const分配内存情况
最新推荐文章于 2022-04-15 09:31:29 发布