Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple 3D Array...

Status
Not open for further replies.

DrkPaladin

Programmer
May 18, 2002
33
CA
Simply, how do I create a 3D array???

Put it in very simple terms Please.

Thanks.
 
Here's an example with an array of int:

int ***array;

to get the (0,0,0) item of that array:

int item;
item = array[0][0][0];

And so on...
But maybe I don't answer very well to your question...
Give more details...
 
declaration of a simple 3d int array;

int value[x][y][z];

example: int number[2][5][8];

and you might need loops to access the array elements.

for( int i = 0; i < 2; i++ )
{
for( int j = 0; j < 5; j++ )
{
for( int k = 0; k < 8; k++ )
number[j][k] = 9
}
}

this will initialise all the elements of the array to &quot;9&quot;.

here is a little program to illustrate all this:

#include <iostream.h>
void main()
{
int number[2][5][8];
int i, j, k;

for( i = 0; i < 2; i++ )
{
for( j = 0; j < 5; j++ )
{
for( k = 0; k < 8; k++ )
number[j][k] = 9;
}
}
// puts all the elements of the array on the screen
for( i = 0; i < 2; i++ )
{
for( j = 0; j < 5; j++ )
{
for( k = 0; k < 8; k++ )
cout<<&quot;number[&quot;<<i<<&quot;][&quot;<<j<<&quot;][&quot;<<k<<&quot;] = &quot;<<number[j][k]<<endl;
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top