Having int array[4][3];
the following applies
array
is an array with 4 elements. Each element is an array with 3 int
s. In most circumstances using the name by itself makes the array decay to a pointer to its first element; then array
becomes a pointer to arrays of 3 int
s
array + 1
is a pointer to an array of 3 ints. Here array
decays to pointer and the 1
refers to array of 3 int
&array
is the address of the whole array. It points to objects of type array of 4 arrays of 3 ints
&array + 1
is the 2nd (which really does not exist) element of a pseudo-array of arrays of 4 arrays of 3 ints
array[0]
is an array of 3 ints. It usually decays to a pointer to the first element
array[0] + 1
points to the 2nd int
in array[0]
&array[0]
address of an object of type array of 3 ints
&array[0]+1
2nd element of an array of arrays of 3 ints
PS. I'll try to make a drawing (ASCII) after lunch.
Hmmm ... drawing is tough :)
Before trying, I thought I could make a better drawing.
This is the best I could come up with ...
int array[4][3] ........[aaabbbcccddd]........
where aaa, bbb, ccc, ddd are arrays of 3 ints'
the [] represent the object itself; the {} represent pointers.
array (object) ........[AAABBBCCCDDD]........ int[4][3]
array (decayed) ==> ........{aaa}bbbcccddd........ int(*)[3]
array + 1 ==> ........aaa{bbb}cccddd........ int(*)[3]
&array ==> ........{aaabbbcccddd}........ int(*)[4][3]
&array + 1 ==> ........aaabbbcccddd{xxxxxxxxxxxx}........ int(*)[4][3]
array[0] (object) ........[AAA]bbbcccddd........ int[3]
array[0] (decayed) ==> ........{a}aabbbcccddd........ int*
array[0] + 1 ==> ........a{a}abbbcccddd........ int*
&array[0] ==> ........{aaa}bbbcccddd........ int(*)[3]
&array[0] + 1 ==> ........aaa{bbb}cccddd........ int(*)[3]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…