int select(const int& num)
{
int* p = const_cast<int*>(&num); //强制去掉const属性
*p = 40;
//num = num - 5; //会出现错误
return num;
}
int main()
{
const int a = 20;
int b = 10;
std::cout << "the num is: " << select(a) << std::endl; //会输出40
std::cout << "the num is: " << select(b) << std::endl; //会输出40
std::cout << "the num is: " << a << std::endl; //输出20
std::cout << "the num is: " << b << std::endl; //输出40
std::cout << "Hello World!\n";
}
常量不会从内存中读取,变量才会从内存中读取