常量指针对于const int *ptr
你不能改变指向的值由PTR混淆使用C
int main()
{
const int *p;
int a=5;
p=&a;
printf("%d",++(*p));
}
上述程序抛出我的错误。这是公平的。
但为什么下面的代码不会给我错误。
int main()
{
const int const *p;
int a=5;
p=&a;
a=100; // changing the content pointed by the constant pointer
printf("%d",(*p));
}
我改变了const指针指向的值。即我将var a的值从 5改为100?
是的。 'a'限定为'const'?诺。那么问题是什么?你是否试图通过指向'const'的指针来改变它?不。然后? – 2013-12-14 05:52:33