下面這個程式的輸出分別是:
1
3
很詭異啊,本來以為這個程式能夠改變常量的值的。。。但是該常量地址里的值明明被改變了啊。。。。
哪位大神知道為什么啊?
#include<iostream>
using namespace std;
void ChangeConst(const int* x)
{
int j =3;
int ** k = (int **)&x;
**k = j;
return;
}
int main()
{
const int x = 1;
const int * p = &x;
ChangeConst(p);
cout << x << endl;
cout << *p << endl;
system("pause");
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/118620.html
標籤:茶館
