为什么我们可以省略多维数组的第一个维度,当我们把它传递给函数 [英] Why can we omit the first dimension of a multidimensional array when we are passing it to a function

查看:115
本文介绍了为什么我们可以省略多维数组的第一个维度,当我们把它传递给函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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).

这篇关于为什么我们可以省略多维数组的第一个维度,当我们把它传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆