根据c ++语法,const int* const p意味着p指向它并且它的值不能被重写.但是今天我发现如果我这样编码:
void f(const int* const p)
{
char* ch = (char*) p;
int* q = (int*) ch;
(*q) = 3; //I can modify the integer that p points to
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,关键字"const"将失去它的效果.使用"const"有什么意义吗?
c++ ×1