|
-
Jul 22nd, 2001, 12:40 PM
#1
Thread Starter
Registered User
-
Jul 22nd, 2001, 12:52 PM
#2
Frenzied Member
To best see the use of a 2D array imagine a chess board. It is like a 2D coordinate system. To mark a field you need two values.
The filed [8][8] would be in the corner. It can also be represented as field[64] but [8][8] is far more unsderstandable.
-
Jul 22nd, 2001, 12:57 PM
#3
Monday Morning Lunatic
Following on from the whole "indirection" theme, a 2D array is basically an array of arrays. For example int x[8] is an array of 8 ints. int x[8][8] is an array of 8 int [x]s.
Am I being clear? I hope so, but probably not because this is nasty stuff
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 22nd, 2001, 01:05 PM
#4
Thread Starter
Registered User
in this example:
Code:
void read(int a[] [5]);
void print(const int a[] [5]);
main()
{
int a[3][5];
read(a);
print(a);
}
void read(int a[][5])
{
//code
}
void print(const int a[][5])
{
//code
}
why don';t you have to say what the first element [ ] is? but u must say waht the 2nd one is.
THe part i don't understand of 2 dimensional arrays is what each means....like for instance..what does this create?
int a[4][5];
does it create 4 groups of arrays with 5 elements in each array?
like
[][][][][]
[][][][][]
[][][][][]
[][][][][]
can u explain it with boxes?
-
Jul 22nd, 2001, 04:54 PM
#5
transcendental analytic
I'm not quite sure what your sample means, i usually don't use arrays, especially not multidimensional. If i'm correct you'd need to specify each but first dimension since to count the distance to an element from the first, you need all but the dimension which is wrapping the others, that is the first.
To understand dimensions you need to understand what a scale is. A dimension is a scale with a unit, and if you have sets of elements (as you call them boxes) they are arrays of that dimension, the scale unit is an element. In a multidimensioned array the elements of the earlier dimension is containing all elements of the next dimension, so if the element you need to access is within the second element of the first dimension, the element is after the last element of the last dimension in the first element of the first dimension. IN a two dimensioned array, you could see it like this:
[1][2][3][4][5]
[6][7][8][9][10]
where [1,0] is the 6'th element, just after the last element in the first.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|