Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Declaring Multi-Dimensional Arrays

Reply
Thread Tools

Declaring Multi-Dimensional Arrays

 
 
joe
Guest
Posts: n/a
 
      12-13-2006
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!


 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      12-13-2006

joe wrote:
> 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..

 
Reply With Quote
 
 
 
 
joe
Guest
Posts: n/a
 
      12-13-2006

"Chris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>
> joe wrote:
>> 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!


 
Reply With Quote
 
joe
Guest
Posts: n/a
 
      12-13-2006

"joe" <(E-Mail Removed)> wrote in message
news:HqLfh.49301$(E-Mail Removed)-nyc.rr.com...
>
> "Chris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
>>
>> joe wrote:
>>> 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;
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
Declaring structs with anonymous arrays andreyvul C Programming 7 09-30-2008 09:36 PM
Declaring/populating variable arrays in ASP.NET??? Friday ASP .Net 35 05-10-2005 06:24 PM
declaring arrays with variable indeces JNY C Programming 6 12-29-2004 12:44 AM
Issues with declaring struct arrays inside of a struct Richard Mathis ASP .Net Building Controls 0 10-10-2003 03:14 PM



Advertisments