C + + learning (1)
1.const C VS C + +:
In the C language , const is a read-only variable (ReadOnly varible), and in C + + Const represents only constants (Constant ).
Cases:
const int n=10;
int Arry[10]//ok in C + + error in C.
2. Two properties of the pointer:
(1). The pointer itself;
(2). The data that the pointer points to;
3. constant pointer and pointer constants:
(1). constant Pointer (point toconstant or constantpoint):
Concept: A pointer to a constant;
Definition:const int* p;
Cases:
const int * p1;
const int x=1;
p1=&x;// Correct
*p1=10;// Error
Here constant refers to the solution reference is a constant;
(2). pointer constant (pointconstant)
Concept: The immutable pointer points to a variable value;
Definition:int* const p;
Cases:
const INT X=1
int* Const p1=&x;// A super important step, be sure to write on P1 who to point to
*p1 = x//or y, also can not write, do not write the words represent the value of the variable that P1 points to;
p1=&y// is wrong because the pointer is not variable in the pointer constant
# The array name is a pointer constant!!
C + + learning (1)