0
Rows and columns?
Are the x,y predefined or depend on how you access the array.?
4 Antworten
+ 8
It depends on how you access the array.
Taking array[x][y], it can be accessed for each x in y, although the norm is to go for each y in x. E.g.
for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 5; y++)
{
// either print array[x][y] or array[y][x] is feasible as long as array index stays inbound and is logically correct
}
}
+ 6
@Rrestoring Faith
I think I meant to say that the concepts of 'rows' and 'columns' represented in 2D arrays can be interchanged according to how the array is accessed. While the first index of an array definitely corresponds to the 'largest box' or the 'outermost frame', the data structure entirely depends on the programmer's mental model.
E.g. Matrices being listed vertically or horizontally.
+ 3
@Hatsy
Maybe I'm wrong but isn't it always [y][x]?
If we have an array:
{4,3,2},{1,2,6}
The first index [c][] will always be which array you are pointing to. (The y array at index c.)
So,
[1][2] is 6.
[2][1] is error.
[1][0] is 1.
[0][1] is 3.
Am I wrong about this, or miss-reading the question? 😜.
+ 3
Ahh alrighty, very true. My bad.