在多维数组中,数组的维数应该大于1。下图展示了一个维数为3 x 3 x 3的多维数组的内存分配策略。

这是一个用C++编写的初始化多维数组的程序。
Begin Initialize the elements of a multidimensional array. Print the size of the array. Display the content of the array. End
#include<iostream>
using namespace std;
int main()
{
int r, c;
int a[][2] = {{3,1},{7,6}};
cout<< "Size of the Array:"<<sizeof(a)<<"\n";
cout<< "Content of the Array:"<<sizeof(a)<<"\n";
for(r=0; r<2; r++) {
for(c=0; c<2; c++) {
cout << " " << a[r][c];
}
cout << "\n";
}
return 0;
}Size of the Array:16 Content of the Array:16 3 1 7 6
以上就是在C/C++中初始化多维数组的详细内容,更多请关注php中文网其它相关文章!
c++怎么学习?c++怎么入门?c++在哪学?c++怎么学才快?不用担心,这里为大家提供了c++速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号