为什么我们可以省略多维数组的第一个维度,当我们把它传递给函数

问题描述:

我们为什么可以忽略,当我们把它传递给函数的多维数组的第一个维度?

Why can we omit the first dimension of a multidimensional array when we are passing it to a function?

在我的编程类,我们被告知哪些传递一个多维数组给函数的时候,我们可以省略第一个维度,例如, A [10] [15] [20] 可为 A [] [15] [20]

In my programming class, we were told what when passing a multidimensional array to a function we can omit first dimension, for example, a[10][15][20] can be passed as a[][15][20].

为什么?

由于阵列将衰减到指针和计算偏移到数组,你不需要知道最里面的维的元素。偏移 A [I] [J] [K] 我* NJ * NK + J * NK + K (其中, NJ NK 对应尺寸)。

Because the array will decay to pointer and to calculate offset to the elements of the array you do not need to know the innermost dimension. Offset to a[i][j][k] is i*nj*nk+j*nk+k (where nj and nk are corresponding dimensions).