473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Declaring Multi-Dimensional Arrays

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!
Dec 13 '06 #1
3 2862

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..

Dec 13 '06 #2
joe

"Chris" <Th*******@gmail.comwrote in message
news:11**********************@79g2000cws.googlegro 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!
Dec 13 '06 #3
joe

"joe" <sw******@hotmail.comwrote in message
news:Hq*******************@news-wrt-01.rdc-nyc.rr.com...
>
"Chris" <Th*******@gmail.comwrote in message
news:11**********************@79g2000cws.googlegro 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;
}
Dec 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
1
by: Maarten Terlingen | last post by:
Sample: ClassA: ClassB ClassB: ClassC ClassA x = new Class C I want to know the declaring type of C. x.GetType() returns C x.GetType().BaseType returns B x.GetType().BaseType.BaseType...
5
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
5
by: param | last post by:
Declaring struct as static is creating problem with newer version of CC compiler 5.7 in solaris. e.g. static struct new_str { int a; int b; };
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
8
by: nguillot | last post by:
Hello. If I have the following classes: class B {}; typedef B tB; if A is: class A
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.