How to declare a three dimensional array
-
I want to know how to declare three dimensional arrays in C/C++ and how they work. Examples will do. Please help.
-
I have been to that site but it only talks about it without examples. I know it can for instance be declared as follows: int rates[10][4][3]; The declaration is what has been shown on the site. But I want to know how to initialise the array when it is declared, and know how the indexing will refer to a particular value in the initialising list.
-
I have been to that site but it only talks about it without examples. I know it can for instance be declared as follows: int rates[10][4][3]; The declaration is what has been shown on the site. But I want to know how to initialise the array when it is declared, and know how the indexing will refer to a particular value in the initialising list.
-
I have been to that site but it only talks about it without examples. I know it can for instance be declared as follows: int rates[10][4][3]; The declaration is what has been shown on the site. But I want to know how to initialise the array when it is declared, and know how the indexing will refer to a particular value in the initialising list.
-
I have been to that site but it only talks about it without examples. I know it can for instance be declared as follows: int rates[10][4][3]; The declaration is what has been shown on the site. But I want to know how to initialise the array when it is declared, and know how the indexing will refer to a particular value in the initialising list.
Dan_K wrote:
But I want to know how to initialise the array when it is declared...
Like:
int Array3D[2][4][6] =
{
{
{ 1,2,3,4,5,6 },{ 7,8,9,10,11,12 }, { 13,14,15,16,17,18 }, { 19,20,21,22,23,24 } }, { { 77,78,79,80,81,82 }, { 83,84,85,86,87,88 }, { 89,90,91,92,93,94 }, { 95,96,97,98,99,100 } }
};
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
I want to know how to declare three dimensional arrays in C/C++ and how they work. Examples will do. Please help.
Use boost::multi_array[^] to create arrays of any dimensions.
«_Superman_»
I love work. It gives me something to do between weekends. -
I want to know how to declare three dimensional arrays in C/C++ and how they work. Examples will do. Please help.
A sample;
int array[3][4][5] = {
{ //[0][][]
{ 1, 2, 3, 4, 5 },//[0][1][]
{ 1, 2, 3, 4, 5 },//[0][2][]
{ 1, 2, 3, 4, 5 },//[0][3][]
{ 1, 2, 3, 4, 5 } //[0][4][]
},
{ //[1][][]
{ 1, 2, 3, 4, 5 },//[1][1][]
{ 1, 2, 3, 4, 5 },//[1][2][]
{ 1, 2, 3, 4, 5 },//[1][3][]
{ 1, 2, 3, 4, 5 } //[1][4][]
},
{ //[2][][]
{ 1, 2, 3, 4, 5 },//[2][1][]
{ 1, 2, 3, 4, 5 },//[2][2][]
{ 1, 2, 3, 4, 5 },//[2][3][]
{ 1, 2, 3, 4, 5 } //[2][4][]
}
};