These two days have been asked many times about this aspect of the problem, I have been not very understanding, and did not answer well, now to sweep their own blind. //The following are mostly reproduced, mixed with a few personal views, if inappropriate please inform.
Array pointers (row pointers)
define INT (*p) [n];
() high priority, the first explanation is that p is a pointer to an integer one-dimensional array, the length of the one-dimensional array is n, it can be said that the step of P. In other words, when executing p+1, p crosses the length of n integer data.
To assign a two-dimensional array to a pointer, you should assign this value:
int a[3][4];
int (*p) [4]; The statement defines an array pointer to a one-dimensional array with 4 elements.
Personal understanding of the bucket structure in similar data structures 4 as the number of elements
P=a; Assign the first address of the two-dimensional array to p, i.e. a[0] or &a[0][0]
p++; After the statement executes, that is, P=p+1;p crosses line a[0][] points to the line a[1][]
For example, to represent an array of I row J columns of an element:
* (P[I]+J), * (* (p+i) +j), (* (P+i)) [j], P[i][j].
Therefore, it is more appropriate to call the array pointer than the row pointer.
This will be an error in writing:
1 int a[2[3]={{1,2,3},{4,5,6 }};2 int (*p) [3];3 p=a;4 for (int i=0;i<3; i++) 5 cout<< (*p) ++<< Endl;
This writes out the address:
1 inta[2][3]={{1,2,3},{4,5,6}};2 int(*p) [3];3p=A;4 for(intI=0;i<3; i++)5cout<<*p++<<endl;
Use:
Pointer arrays are often used to point to several strings, which makes string processing more flexible and convenient.
Array of pointers
define int *p[n];
n An array of pointer elements of type int.
int a=1,b=2,c=3;
int *p[3]={&a,&b,&c};
Output:
P At this point is a pointer to an array pointer, so the values are different from p[0].
when it was written to P[5], it collapsed. (why?) )
Array pointers and array of pointers