Constant pointer pointing to: the pointer value can not be changed, the pointer is not constant, it is possible to modify the pointer
int main(void)
{
int value = 10;
/*定义一个指向常量的指针*/
const int *pValue = &value;
//pValue = &value;
/**
*
* 编译器会报错,*pValue是只读的。
* 也就是指针指向的值不能改变
*/
/**
* 这个赋值编译器会报错 assignment of read-only location '*pValue'
* 因为*pValue指向的值是常量,所以不能改变。
*/
*pValue = 20;
/*但可以对value的值进行改变*/
int number = 30;
/**
* 指针不是常量,所以可以修改指针的指向
*/
pValue = &number;
return 0;
}
Constant pointer
#include <stdio.h>
/**
- Const pointer
-
Stored address pointer can not be changed
/
int main (void)
{
int value = 10;
int const = & pValue value;int item = 34;
/**- Compiler error, assignment of read-only variable 'pValue'.
- DESCRIPTION can not modify the address stored in the pointer
/
pValue = & Item;
/ may be modified address value points /
pValue = 24;
return 0;
}