First, the representation method of multi-dimensional array addresses
There is an integer two-dimensional array a [3] [4] as follows:
0 1 2 3 4 5 6 7 8 9 10 11
The first address of the unit A is 1000, the first address of each subscript and its value are shown in the figure. In the previous introduction, the C language allows a two-dimensional array to decompose into multiple one-dimensional arrays. Therefore, array A can be broken down into three one-dimensional arrays, namely A [0], A [1], A [2]. Each one-dimensional array has four elements. For example, a [0] array contains A [0] [0], A [0] [1], A [0] [2], A [0] [3] four elements. The address of the array and array elements is shown below: A is a two-dimensional number of group names and the first address of the 2D array 0 row, equal to 1000. A [0] is the number of group names and first addresses of the first one-dimensional array, so it is also 1000. * (A 0) or * a is equivalent to A [0], which represents the first-dimensional array a [0] No. 0 element. Also 1000. & a [0] [0] is the 0 row of 0 rows of two-dimensional array A, which is also 1000. Therefore, A, A [0], * (A 0), * a, & a [0] [0] are equal. Similarly, A 1 is the first address of the two-dimensional array 1 line, equal to 1008. A [1] is the number of group names and first addresses of the second one-dimensional array, so it is 1008. & a [1] [0] is a 1 line 0 column element address of the two-dimensional array A, is also 1008. Therefore, A 1, A [1], * (A 1), & a [1] [0] is equivalent. This can be obtained: A I, A [I], * (A I), & a [i] [0] is equivalent. In addition, & a [i] and a [i] are also equivalent. Because the & a [i] cannot be understood as the address of Element A [I] in the two-dimensional array, there is no element a [i].
C language regulations, it is an address calculation method that represents an array A X-line address. As a result, we conclude: a [i], & a [i], * (a i) and a i are also equivalent. In addition, A [0] can also be regarded as a first address of the No. 0 element of one-dimensional array a [0], and a [0] 1 is an element of A [0] The first address, thereby obtaining a [i] j is a one-dimensional number of group J, the first address, which is equal to & a [i] [j]. A [i] = * (A i) is a [i] j = * (A I) J, due to * (A I) J is the i line J column elements of the two-dimensional array A First address. The value of this element is equal to * (* (A I) J).
[Explain]
#define pf "% D,% D,% D,% D,% D, / N" main () {static int A [3] [4] = {0, 1, 2, 3, 4, 5, 6 , 7, 8, 9, 10, 11}; Printf (PF, A, * A, A [0], & A [0], & A [0] [0]); Printf (PF, A 1, * ( A 1), A [1], & A [1], & A [1] [0]); Printf (PF, A 2, * (A 2), A [2], & A [2], & A [2] [0]); Printf ("% D,% D / N", A [1] 1, * (A 1) 1); Printf ("% D,% D / N", * (A [1] 1), * (* (A 1) 1);