版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011930705/article/details/78969489
这段代码,constant和next、ptr地址相同,但是他们的值不同,具体原理不太明白,但是使用还是比较好用的
#include <iostream>
using namespace std;
int main()
{
const int constant = 21;
const int *ptr = &constant;
//int constant = 21;
int* next = const_cast<int *>(ptr);
//int *next = &constant;
*next = 7;
cout << next <<endl;
cout << ptr<< endl;
cout << *next <<endl;
cout << *ptr<< endl;
cout << &constant << endl;
cout << constant<< endl;
return 0;
}