卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章20330本站已运行347

在C/C++中初始化多维数组

<?xml encoding="utf-8" ?>

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

在C/C++中初始化多维数组

这是一个用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
卓越飞翔博客
上一篇: php设计后台主要有哪些方面
下一篇: 返回列表
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏