C language pointer to constant and constant pointer
A pointer to a constant: the value of the pointer cannot be changed, and the pointer is not a constant, so the pointer can be modified.
Int main (void) {int value = 10; / * define a pointer to a constant * / const int * pValue = & value; / / pValue = & value; / * * the compiler will report an error and * pValue is read-only. * that is, the value pointed to by the pointer cannot be changed * / / * * the assignment compiler will report an error assignment of read-only location'* pValue' * because the value pointed to by * pValue is constant, so it cannot be changed. * / * pValue = 20; / * but you can change the value of value * / int number = 30; / * the pointer is not constant, so you can change the pointer to * / pValue = & number; return 0;}
Constant pointer
# include
/ * *
Constant pointer
The address stored in the pointer cannot be changed
/
Int main (void)
{
Int value = 10
Int const pValue = & value
Int item = 34
/ * *
Compiler error, assignment of read-only variable 'pValue'. Indicates that the address stored in the pointer cannot be modified
/
PValue = & item
/ but you can modify the value pointed to by the address /
PValue = 24
Return 0
}