2 Dimensional Array
The following piece of code bothers me...
// demonstrates creating a multidimensional array
// This creates a 2 dimensional array. The first dimension is a set of numbers
// from 0 to 4. The next dimension consists of the double of each value of the
// first dimension
#include ''iostream.h''
int main()
{
int SomeArray[5][2] = { {0,0}, {1,2}, {3,6}, {4,8} };
for (int i=0; i<5; i++)
for (int j=0; j<2; j++)
{
cout << "SomeArray[" << i << "][" << j << "]: ";
cout << SomeArray[j] << endl;
}
return 0;
}
int SomeArray has two subscripts- one 5 and the other 2. The subscripts are initialized in the braces right after the declaration, but here''s what I don''t get: the SomeArray[2] is only allowed to have 3 values, yet it is initialized 5 different times in the braces right after its initialization. I''m wrong, but isn''t this ''writing-passed-the-array''? This whole block of code is really confusing to me... since I last posted, Arrays in general were giving me a hard time- but I got''em down. Now 2d? aw god... anyways, could anyone help me with this really annoying piece of code?
Programming::~Fredric(const Annoy_Ance)
3D Math- The type of mathematics that'll put hair on your chest!
Jibberish I tell you! Jibberish!
Did I list this right? I need sleep, as we all probably do. Where in ontario are you from? I live in Burlington.
Edited by - Gromit on 3/1/00 1:26:25 AM
SomeArray[5][2] = { {0,0}, {1,2}, {2,4}, {3,6}, {4,8} };SomeArray[0][0] = 0;SomeArray[0][1] = 0;SomeArray[1][0] = 1;SomeArray[1][1] = 2;SomeArray[2][0] = 2;SomeArray[2][1] = 4;SomeArray[3][0] = 3;SomeArray[3][1] = 6;SomeArray[4][0] = 4;SomeArray[4][1] = 8;
Did I list this right? I need sleep, as we all probably do. Where in ontario are you from? I live in Burlington.
Edited by - Gromit on 3/1/00 1:26:25 AM
Who in the smegging hell wrote that code?
source
source
#include "iostream.h"int main(void){ int SomeArray[5][2] = { {0,0}, {1,2}, {2,4}, {3,6}, {4,8} }; for (int i=0; i<5; i++) for (int j=0; j<2; j++) cout << "SomeArray[" << i << "][" << j << "]: " << SomeArray[j] << endl;<br> return 0;<br>}<br> </pre> <br><br><i>output </i> <br><pre><br>SomeArray[0][0]: 0<br>SomeArray[0][1]: 0<br>SomeArray[1][0]: 1<br>SomeArray[1][1]: 2<br>SomeArray[2][0]: 2<br>SomeArray[2][1]: 4<br>SomeArray[3][0]: 3<br>SomeArray[3][1]: 6<br>SomeArray[4][0]: 4<br>SomeArray[4][1]: 8<br> </pre> <br><br><br><i>..hmm, must remember, square braces around an I start italics. nb: do not use in code when posting. </i> <br><br>Edited by - Veldrik on 3/1/00 6:10:26 AM
After both Gromit & Veldrik typing that up you should understand...It quite simple really.
//--- Created by Tom Oram ---
// tom.oram@vodafone.net
//--- Created by Tom Oram ---
// tom.oram@vodafone.net
Gromit- I''m from Pickering Ontario. I''ve heard of Burlington, I''m not sure if I''ve been there before thoughh.
Thanks for the help everyone
Programming::~Fredric(const Annoy_Ance)
Thanks for the help everyone
Programming::~Fredric(const Annoy_Ance)
3D Math- The type of mathematics that'll put hair on your chest!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement