To illustrate:
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:
#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;
}
(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 and 2 columns , which can be used:
#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;
}
}
Attention:
(1) To determine the number of rows, the number of columns is uncertain, that is, 2*n type.
(2) A pointer usage for an array of type n*2, the number of rows is indeterminate, and the number of columns is determined.
for (1) its equivalent form is as follows:
#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;
}
In fact, the usage of this dynamic two-dimensional array is our common use
The difference between int*p[] and int (*p) []