The difference between pointers and reference operators
Pointers and references are similar concepts, but they are not the same. They all point to an object, but the pointer can allow that point to change at any time, and it allows you to point to an empty object. A reference is not the same, the reference must initially point to an object, and this point can never change, that is, can always point to this object, can not be changed. As you can see, the pointer is the point of a variable, and the reference is the point of a constant.
Pointers and references are also different in operation, and pointers use operators * and->, referencing the use of Operators & and. (dots).
For example, when they are defined, they use different operators:
Define pointer: int *number; can be assigned without initial value
Definition Reference: string s = "Hangcool";
string& PS = s; The value must be initially assigned so that the PS points to S.
Use a different operator when you point to a member of a variable:
Pointer pointing: x->y; The member Y pointing to the X pointer;
Reference point: x.y; Points to the member y referenced by X;
Of course, we can also write this: (*x). Y is equivalent to x->y.
It must be clear in the concept of the pointer that x represents an address value that points to an address, and *x represents a variable value that points to an address.
In addition, they have an important purpose in addition to the use of * and & in defining pointers and references:
Using * and & before variables have different meanings:
*: called a reference operator. That represents the content to be taken by the address that the expression represents. It can be translated as "... The value to point to ("value pointed by").
For example, * Mypointer can be read as "Mypointer pointing value".
&: Called an address or dereference operator. It is used as a variable prefix that can be translated as "... "(" Address of "),
For example, &variable1 can be read as a variable1 address. From: Blog.csdn.net/acosoft