常量指針對於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