An example is provided:
1) int* p[2] is an array of pointers to int, that is: P is an array of pointers containing two elements, and the pointer is to an int type.
You can use this to:
Copy Code code as follows:
<span style= "Background-color:rgb (255,255,255)" > #include <iostream>
using namespace Std;
int main (int argc, char* argv[])
{
int* p[2];
int a[3] = {1, 2, 3};
int b[4] = {4, 5, 6, 7};
P[0] = A;
P[1] = b;
for (int i = 0; i < 3; i++)
cout << *p[0] + i;//cout << **p + i;
cout << Endl;
for (i = 0; i < 4; i++)
cout << *p[1] + i;//cout << **p + i;
return 0;
}</span>
2 for Int (*p) [2], it is equivalent to the use of a two-dimensional array, except that it is an array of n rows 2 columns that can be used:
Copy Code code as follows:
<span style= "Background-color:rgb (255,255,255)" > #include <iostream>
using namespace Std;
void Main () {
int (*p) [2];
int b[3][2] = {1, 2}, {3, 4}, {5, 6}};
p = b;
for (int i = 0; i < 3; i++) {
for (int j = 0; J < 2; j + +)//cout << p[i][j]; cout << * (* (p+i) +j);
cout << Endl;
}
}</span>
Note:
(1) The number of rows is determined and the number of columns is indeterminate, that is 2*n type.
(2) The pointer usage of an array of n*2 type, the number of rows is indeterminate and the number of columns is determined.
for (1) the equivalent form is as follows:
Copy Code code as follows:
<span style= "Background-color:rgb (255,255,255)" > #include <iostream>
using namespace Std;
void Main () {
int** Array;
Array = new int* [2];
int a[3] = {1, 2, 3};
int b[4] = {4, 5, 6, 7};
Array[0] = A; *array = A;
ARRAY[1] = b; * (array+1) = b;
for (int i = 0; i < 3; i++) cout << array[0][i];//cout << *array[0] + i;
cout << Endl;
for (int j = 0; J < 4; j +) cout << array[1][j];//cout << *array[1] + j;
}</span>
In fact, the above usage is the use of our commonly used dynamic two-dimensional array.