Declaring Multi-Dimensional Arrays

J

joe

hi all,

I have perused the internet a bit and don't see a simple beginner's answer.
All I need right now is how to declare a multi-dimensional array in C++.

// one dimensional array - simple enough
int array[4] = {0,0,0,0};

// two dimensional array - ?
int array[4][5] = {0,0,0,0 ... ?

thx!
 
C

Chris

joe said:
hi all,

I have perused the internet a bit and don't see a simple beginner's answer.
All I need right now is how to declare a multi-dimensional array in C++.

// one dimensional array - simple enough
int array[4] = {0,0,0,0};

// two dimensional array - ?
int array[4][5] = {0,0,0,0 ... ?

thx!

try:

int array[2][2] { { 1, 2 },
{ 3, 4} };

that should give you the idea..
 
J

joe

Chris said:
hi all,

I have perused the internet a bit and don't see a simple beginner's
answer.
All I need right now is how to declare a multi-dimensional array in C++.

// one dimensional array - simple enough
int array[4] = {0,0,0,0};

// two dimensional array - ?
int array[4][5] = {0,0,0,0 ... ?

thx!

try:

int array[2][2] { {1, 2},
{3, 4} };

that should give you the idea..

I see it, thx!
 
J

joe

joe said:
Chris said:
hi all,

I have perused the internet a bit and don't see a simple beginner's
answer.
All I need right now is how to declare a multi-dimensional array in C++.

// one dimensional array - simple enough
int array[4] = {0,0,0,0};

// two dimensional array - ?
int array[4][5] = {0,0,0,0 ... ?

thx!

try:

int array[2][2] { {1, 2},
{3, 4} };

that should give you the idea..

I see it, thx!

// arr4: passes a multidimensional array as a paramter
//
// 12/12/06
// 9:11 PM

// This worked just fine. Thanks again! :)

#include <iostream>
using namespace std;

// DECLARATIONS
void printArray (int arg[][3][3], int i, int j, int k)
{
cout << "\n";
for (int n = 0 ; n < i ; n++)
{
for (int m = 0 ; m < i ; m++)
{
for (int l = 0 ; l < i ; l++)
{
cout << " " << arg[n][m][l] << " ";
}
cout << "\n";
}
cout << "\n";
}
cout << "\n";
}

int main ()
{
// INPUT
int array1[3][3][3] = { { { 1, 2, 3}, { 4, 5, 6}, { 7, 8, 9} },
{ {10, 11, 12}, {13, 14, 15}, {16, 17, 18} },
{ {19, 20, 21}, {22, 23, 24}, {25, 26, 27} }
};

// CALCULATIONS


// OUTPUT
printArray(array1, 3, 3, 3);


// EXIT
cout << "\n done.\n";
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top