Pointer:
Many people know that pointers are the address of a stored variable, and sometimes it's quite confusing to think about it.
Array:
The array name is actually an address that points to the first address of the array.
Question 1 So how do I use pointers to manipulate arrays?
int main () {int Arr[3]={3,5,9};int *ptr1[3] = {nullptr};int (*PTR2) [3] = &ARR;//OK*PTR1 = &ARR[0];//OK//*PTR1 = &am p;arr//errorfor (int i=0; i<3;i++) {cout<< (*PTR2) [i]<<endl;//okcout<<ptr2[i]<<endl;cout << (*PTR1) [I]<<endl;//okcout<<ptr1[i]<<endl;} printf ("%d", sizeof (short)); System ("pause"); return 0;}
If you still have questions:
So, array pointers, pointers arrays look at the instructions below.
int *arry[10]; pointer array int (*ARRYP) [ten]; An array pointer, since the array pointer points to an array, and the array can be seen as a pointer, the array pointer can be interpreted as a level two pointer int a[10]; Arryp = &a; Sets the array of address number of pointer arry[0] = *ARRYP; Arry[0] is a first-class pointer, to assign an array pointer to an array of pointers, the content should be taken, the actual is arry[0] = A;
Tip: Array allocation is a continuous address, so
*PTR1 = &arr[0];//ok
You can also remove the values consecutively.
Second-level pointers:
The pointer is also an object, and the object has its own address, and the pointer can also assign a value to the pointer address.
int P1 = *p2 = &p1; int **p3 = &p2;cout<<p1<<endl;cout<<*p2<<endl;cout<< **p3<<endl;
The diagram is as follows:
P3--------------------------->p2----------------------------->p1 (100)
Reference:
The reference itself is not an object, then there is no address, and there is no pointer to the reference.
It also shows that there is a reference to the pointer.
C + + (suspect 1) arrays and pointers