Const modifies a read-only variable, not a constant, whose value cannot be used at compile time because the compiler does not know what it is storing at compile time. The compiler usually does not allocate storage space for ordinary const read-only variables, but keeps them in the symbol table, which makes him a compile-time value, without the storage and memory operations, making it highly efficient.
For example:
#define M 3//Macro constant
const int n=5; N is not put in memory at this time
······
int n=i; n allocates memory at this time and is no longer assigned
int i=m; Macro substitution during precompilation, allocating memory
int j=n; No memory allocated
int j=m; To replace the macro again and allocate memory again
It is known that a const-defined read-only variable has only one copy of the program running (because it is a global read-only variable, stored in the static area), and the macro constants defined by # define have several copies in memory.
#define宏是在预编译期间进行替换, no type
A const-Modified read-only variable has a specific type, which determines its value at compile time.
Const modifier pointer:
const int *p; P variable, p-pointing object is not variable
int const *P; P variable, p-pointing object is not variable
int *const p; P is immutable, the object to which P points is variable
const int *const p; The P and P objects are not variable
How to interpret it?
Ignore the type name (compiler parsing will also be ignored type name), see the const from which to go, who is near to decorate who.
The const and define of C language