int *p;
P=new Int[3];
P[0]=1;
p[1]=2;
p[2]=3;
&p, *p, p, * (&P) What does each of these three mean?
Here, new int[3] Returns a pointer to the exact type of object requested, which is exactly the address of the first element of the array, that is, the first address of the value.
So &p is the address of the pointer p, which is the address of the pointer to the first address of the array.
*p: The * is used for the indirect reference of pointers (the third use of *, the other two usages are: multiplication and defining pointers). When you indirectly reference a pointer, you get the variable content pointed to by the pointer. Here is the first element of the array to get the contents, that is, 1;
P: Is the first address of the array.
* (&P): Gets the contents of the pointer p address, which is the content that points to the first address of the array.
A draft was drawn at the fingertips. A little ugly, it will look.
The code is as follows:
#include <iostream>using namespace Std;int main () {int *p;p=new int[3];p [0]=1;p[1]=2;p[2]=3;cout<<&p <<endl; Gets the address of the pointer p, which is the address of the pointer to the first address of the array cout<<* (&P) <<endl;//Gets the contents of the pointer p address, that is, the contents of the first address of the array. cout<<*p<<endl;//gets the contents of the address that the pointer points to cout<<p<<endl; Gets the contents of the pointer p stored for (int i=0;i<3;i++) {cout<<&p[i]<< "\ t" <<P[I]<<ENDL;}
Operation Result:
、
Personal opinion, wrong to welcome correct.
What does &p, *p, p, * (&p) mean?