Const keyword and pointer, const keyword pointer
Four cases of const and pointer combination
The four situations are as follows:
Int cons * p itself is not a constant, and p points to the address of the data is a constant
Const int * p itself is not a constant, and p points to the address of the data is a constant
Int * const p is a constant, and p points to an address space that is not a constant.
Const int * const p is a constant, and the address space pointed to by p is also a constant
Summary: When const is on the left side of *, it modifies the data of the address pointed by p. When const is on the right side of *, the modified p
When a variable is modified with const, the value of the variable can still be modified with the pointer in gcc.
Int main (void)
{
Const int a = 5;
// A = 6; // error: assignment of read-only variable 'A'
Int * p;
P = (int *) & a; // The alert height here can be eliminated by force type conversion
* P = 6;
Printf ("a = % d. \ n", a); // a = 6, the result shows that the const type variable is changed
Return 0;
}