Constant: Only data occupies storage space, but after compilationCodeOnly reference data, no address concept. For example:
Const string HI = "hello ";
Const int days = 31;
Variable: the data stored in the memory (right value). The address (left value) needs to be referenced during modification. For example:
Int num = 12;
Float d = 354.333f;
Bool B = true;
The pointer should focus on three values: the memory address for storing the pointer variable, the memory address pointed to by the pointer, and the value pointed to by the pointer.
If a pointer variable is defined:
Int num = 8;
Int p * = & num;
The three values are expressed as: & P, P, * P.
Example:
Int main () {int * P = NULL; cout <"not assigned after initialization:" <Endl; cout <"pointer variable address (& P) = "<& P <Endl; cout <" pointer to address (p) = "<p <Endl; If (P! = NULL) cout <"pointer to address storage value (* P) =" <* P <Endl; elsecout <"null pointer, cannot be set. "<Endl; P = new int (1024); cout <" after assignment: "<Endl; cout <" pointer variable address (& P) = "<& P <Endl; cout <" pointer to address (p) = "<p <Endl; If (P! = NULL) cout <"pointer to address storage value (* P) =" <* P <Endl; elsecout <"null pointer, cannot be set. "<Endl; Delete P; P = NULL; cout <" after release: "<Endl; cout <" pointer variable address (& P) = "<& P <Endl; cout <" pointer to address (p) = "<p <Endl; If (P! = NULL) cout <"pointer to address storage value (* P) =" <* P <Endl; elsecout <"null pointer, cannot be set. "<Endl; return 0 ;}
You can clearly understand the relationships and differences between the three.
Note: it is best to assign null values when defining a pointer, and assign null values when releasing the pointer (delete). In this way, some incorrect pointer actions can be avoided.