我知道在某些情况下,指针的指针被描述为一个矩阵。有人可以解释,为什么这个工程呀?其中 C 属性允许呢?
I know that in some cases, pointer to pointer is described as a matrix. Can somebody explain, why this works in that way? Which C property allows it?
请不要张贴这样的答案,如指针的指针并不总是矩阵。的我知道,但我问为什么它在某些情况下,一个矩阵。
Please do not post such answers as Pointer to pointer not always matrix. I know that, but I am asking why it is a matrix in some situations.
推荐答案[] 在线实现。 A [B] 其实就是 *(A + B)
Because of opeator [] inline implementation. a[b] actually is *(a + b)
所以,第一个 [] 选择了行和第二选择列。因此,它是改编[M] [N] 同的StepOne = *(ARR + M),其中 M = M *ñ和 stepTwo =的StepOne [N] ,
So the first [] chooses the row and the second chooses the column. So it is arr[m][n] the same as stepOne = *(arr + M) where M = m * n and stepTwo = stepOne[n],
这是一样的 *(的StepOne + N)。因此,这条产业链,我们看到后什么改编[M] [N] 相同 *(ARR M * N + N)
which is the same as *(stepOne + n). So after this chain we see what arr[m][n] is the same as *(arr m*n + n)
要确认什么是真正的可以检查这个短节目
To confirm what is true you can check this short program
int main() { char arr[10][15]; std::cout << sizeof(arr) << std::endl; //150 std::cout << sizeof(*arr) << std::endl; //15 std::cout << sizeof(arr[0]) << std::endl; //15 std::cout << sizeof(*arr[0]) << std::endl; //1 std::cout << sizeof(**arr) << std::endl; //1 std::cout << sizeof(arr[0][0]) << std::endl; //1 std::cout << arr << std::endl; //some number std::cout << arr+1 << std::endl; //some number + 15 std::cout << &arr << std::endl; //some number std::cout << &arr+1 << std::endl; //some number + 150 return 0; } +---+---+---+---+---+---+---+ This is matrix: | E | | | | | | | +---+---+---+---+---+---+---+ | | | | | | | | +---+---+---+---+---+---+---+ | | | | | | | | +---+---+---+---+---+---+---+ | | | | | | | | +---+---+---+---+---+---+---+ | | | | | | | | +---+---+---+---+---+---+---+ | | | | | | | | +---+---+---+---+---+---+---+我标志着入境信函E.比方说这是 INT M [6] [7] 。所以,让我们去反向方式。
I marked entry letter E. Lets say this is int M[6][7]. So lets go reverse way.
因此,为了使图出了这一切:
So to make a graph out of all this:
+---+---+---+---+---+---+---+ M[0] ----> | E | | | | | | | +---+---+---+---+---+---+---+ +---+ M[0][0] ----> | E | +---+我希望图的帮助,因为我在解释这个东西可不是那么好...
I hope graph help because I'm not so good in explaining this stuff...
BTW 一件事,指针的指针并不总是一个矩阵。
BTW One more thing, pointer to pointer not always a matrix.
更多推荐
为什么指针,指针是一个矩阵?
发布评论