简体   繁体   English

静态多维数组(C / C ++)

[英]Static Multi Dimensional Arrays ( C/C++)

Is memory allocated for multidimensional arrays in C or C++ always contiguous, or is the storage dependent on the compiler? 为C或C ++中的多维数组分配的内存是否总是连续的,还是存储依赖于编译器? If it is guaranteed to be contiguous is there a standard on it somewhere for reference? 如果保证是连续的,是否在某处有参考标准? For example 例如

int x[2][2] = { { 1 , 2 } , { 5 , 10 } } ;

Are the integers 1, 2, 5, 10 in sequence in memory ? 内存中的整数1、2、5、10是否按顺序排列?

Arrays are guaranteed contiguous. 保证数组是连续的。 What we have here is an array of arrays - each layer of which is contiguous. 我们这里是一个数组数组-每个图层都是连续的。 The inner most arrays we know must be {1, 2} and {5, 10} , and the outer most array must also be contiguous. 我们知道的最里面的数组必须是{1, 2}{5, 10} ,最外面的数组也必须是连续的。 Therefore, {{1,2},{5,10}} must be 1, 2, 5, 10 sequentially in memory. 因此, {{1,2},{5,10}}在内存中必须依次为1、2、5、10。

Yes. 是。 Arrays are always allocated in contiguous memory location. 数组始终分配在连续的内存位置。 It doesn't matter whether its a single or multi dimensional array. 它是一维数组还是多维数组都没有关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM