In C ++, * has three usage methods:
1) multiplication number, for example, a * B;
2) pointer type, for example, int * P;
3) value of the pointer type variable, for example, int B = * P.
(1) * is an independent binary operator. It does not have a special meaning for the two variables before and after;
For 2), we should regard "int *" as a new type, int pointer type. P is the name of the variable, and "int *" is the type of the P variable. That is to say, * can be used with any class or type to form a new type of "classname *" or "typename. This new type indicates a memory address segment by the name of the first half and * of the second half:
* It indicates that the value of P is the starting position of a memory address segment (for 32-bit operating systems, P is an 8-bit hexadecimal number );
Name indicates the length of the memory address indicated by P, which is the size of the class or type.
* P indicates that this variable is a pointer type and stores a memory address (the starting address of a certain data in the memory), but most of the time this does not make any sense. We need to know the length of the data in the memory, which is determined by the class or type in front, the p type will change from the "pointer type" to a meaningful "pointer type ".
For * in 2), it does not have any meaning when it exists independently, nor does it make sense to append it to variable name P. It is complete only after being attached to a class or type.
3), * is a unary operator. Its operands must be of a pointer type, and it returns a value of a certain type.
For encoding habits of 2) and 3), I like to use the following space format:
Int *P = &;
Int B =* P;
And do not like to use
Int * P = &;
Int B = * P;