如何声明和在C 4维数组初始化 [英] How to declare and initialize in a 4-dimensional array in C
问题描述
我是比较新的编程,我需要在4维数组进入,我只能勉强换我的头周围。所以,让我们从一个简单的3-D阵列,每个像这样2个元素:
I'm relatively new to programming, and I need to enter in a 4-dimensional array, and I can barely wrap my head around it. So, let's start with a simple 3-d array, 2 elements each like so:
int arr[2][2][2] =
{
{
{1, 2}
{3, 4} //redline on "{"
}
{ //redline on "{"
{5, 6}
{7, 8}
}
};
VS-2012红线的{3,并说之前的期待}代替。我怎么就能够在一个整洁格式输入阵列?有4个尺寸将使它更复杂,我需要能够清楚地看到的数据。
VS-2012 redlines the "{" before the "3", and says it's expecting a "}" instead. How would I be able to enter the array in a neat format? Having 4 dimensions will make it more complicated, and I need to be able to see the data clearly.
另外,我要在我的阵列好多个零的,在本质论每ARR [N] [N]为0,所以我想知道如果我可以做初始化稍微简单一些。
Also, I'm going to have a good number of zeroes in my array, in essense every arr[n][n] will be 0, so I'm wondering if I can make the initialization a little simpler.
我的数组将是类型
int arr[7][7][15][2]
还是我最好使用结构呢?
Or am I better off using struct instead?
在此先感谢!
推荐答案
您错过一个,
。
有关的三维阵列
int arr[2][3][4] = {
{
{1, 2, 1, 2}, {1, 2, 1, 4}, {1, 2, 4, 4}
},
{
{1, 1, 2, 4}, {1, 2, 1, 4}, {1, 2, 1, 4}
}
};
or int arr[2][3][4] = {1,2,1,2,1,2,1,4,1,2,4,4,1,1,2,4,1,2,1,4,1,2,1,4};
有关四维阵列
int arr[2][3][4][2] = {
{
{
{1,2},{1,2},{1,2},{4,2}
},
{
{2, 4},{1, 4},{1, 4},{1,2}
},
{
{2, 4},{1, 4},{1, 4},{1,8}
}
},
{
{
{1,2},{1,2},{1,2},{4,2}
},
{
{2, 4},{1, 4},{1, 4},{1,2}
},
{
{2, 4},{1, 4},{1, 4},{1,2}
}
}
};
这篇关于如何声明和在C 4维数组初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!