C ++ Learning (1), Learning
C ++ Learning (1)
1. const c vs c ++:
In c, const is a read-only variable (ReadOnly Varible). In c ++, const only represents a Constant (Constant ).
Example:
Const int n = 10;
Int arry [10] // OK in c ++ error in c.
2. Two attributes of the pointer:
(1). pointer itself;
(2) Data pointed to by the pointer;
3. Constant pointers and pointer constants:
(1 ).Constant pointer(Point to constant or constant point ):
Concept: pointer to a constant;
Definition: const int * p;
Example:
Const int * p1;
Const int x = 1;
P1 = & x; // correct
* P1 = 10; // Error
Here, a constant refers to a constant for the solution reference;
(2 ).Pointer constant(Point constant)
Concept: an immutable Pointer Points to a variable value;
Definition: int * const p;
Example:
Const int x = 1
Int * const p1 = & x; // super important step. Be sure to write to whom p1 points.
* P1 = x // or y. You can leave it empty. If you leave it empty, it indicates the value of the variable pointed to by p1;
P1 = & y // incorrect, because the pointer in the pointer constant cannot be changed.
# The array name is a pointer constant !!