1. The value defined by const cannot be changed, similar to java final.
[Html]
# Include "stdio. h"
Main (){
Int const x = 15;
X = 16;
Printf ("% d \ n", x );
}
Output:
[Html]
Pateo @ pateo-B86N53X :~ /Work/study $ cc main. c-o main
Main. c: In function 'main ':
Main. c: 6: error: assignment of read-only variable 'X'
2. pointer Constants
[Html]
# Include "stdio. h"
Main (){
Int a = 3;
Int B = 6;
Int c = 9;
Int const * p = &;
Int * const p1 = & B;
Int const * const p2 = & c;
P = & B;
// * P = 4;/** error, error: assignment of read-only location '* P '**/
A = 4;
// P1 = & a;/** error, error: assignment of read-only location 'p1 '**/
* P1 = 5;
B = 7;
P2 = & c;/** error, error: assignment of read-only location 'p2 '**/
* P2 = 8;/** error, error: assignment of read-only location '* p2 '**/
C = 3;
}
Conclusion: in particular, we can basically understand the relationship between the const and the pointer from the column sub of the pointer constant.