Go directly to the code, and the explanation is clear.
C++primer.cpp: Defines the entry point of the console application. #include "stdafx.h" #include <iostream>using namespace Std;int (*function (int i)) [10];//function that returns an array pointer int main () {cout << "arrays, pointer arrays, array pointers, functions that return array pointers:" <<endl<<endl;int arr[10]; Declares an array, an array element is Intint *p1[10];//declares an array, an array element is a pointer to int (*P2) [10];//declares a pointer to an array containing 10 shapes, and the P2 itself is a pointers for (int i = 0; i <; I + +) Arr[i] = i;for (int i = 0; i < ten; i++) cout<<arr[i]<< "";cout<<endl<< "arr:" <<arr<& lt;endl;//Output First address cout<< "&arr[0]:" <<&arr[0]<<endl;//output first element address cout<< "*arr:" << *arr<<endl;//output The first address points to the value of the element, which is the value of the first element cout<< "* (arr+1):" <<* (arr+1) <<endl<<endl;// By the addition of the pointer to the output element value cout<< "to P1 assigned to the address of the ARR element and output:" <<endl;for (int i = 0; i <; i++)///can also be &arr[i]p1[i] = arr+i; for (int i = 0; i < i++) cout<<p1[i]<< "" ";cout<<" the output array by referencing the elements in the P1 arr: "<<endl;for (int i = 0; I < 10; i++)//p1 is stored in the address cout<<*p1[i]<< "";cout<< "pointer to the array P2 assignment to ARAddress of R: "<<ENDL;P2 = &arr;//assigns a value to the pointer, P2 stores the address of arr cout<<" P2: "<<p2<<" << "*P2:" << Why is *p2<<endl;//the same? cout<< "P2[i]:" <<endl;for (int i = 0; I < 10; i++)//This visit is meaningless because it is out of bounds. P2[i] Compiler interpreted as * (p2+i) cout<<p2[i]<< ""; And P2 is just an address, there is no meaning, it is followed by the element is not an array, with P2 no relationship cout<< "*p2[i]:" <<endl;for (int i = 0; I < 10; i++) cout<<*p2[i]<< "";//Ibid., referring to the above address, has crossed access, there is no meaning cout<< "(*P2) [i]:" <<endl;for (int i = 0; I < 10; i++) cout<< (*P2) [i]<< "";//equivalent to Arr[i]return 0;}
Paste the results:
Relationships of arrays, pointer arrays, array pointers, functions that return array pointers