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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

3 dimensional array 1

Status
Not open for further replies.

xlav

Technical User
Oct 23, 2003
223
JM
Trying to declare and initialize a 3 dimensional array but can't get it right. Any help appreciated.

-X
 
In C++ declare 3D arrays like this:

int 3D[width][length][height];

i.e.

int 3D[5][5][5];

Then obviously you would access the data like so:

int 3D[5][1][3] = 10;

-Bones
 
Code:
int a[3][4][2]=
{
	{{0,0},{0,0},{0,0},{0,0}}
	,{{0,0},{0,0},{0,0},{0,0}}
	,{{0,0},{0,0},{0,0},{0,0}}
};
-obislavu
 
Thanks for your reply. Example given by obislavu is very helpful.

-X
 
you could also do it like this:
Code:
int a[2][5][6] = {0};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top