0

Multi-dimensional array

I don't understand how the code works. int x[2][3] = {{2, 3, 4}, {8, 9, 10}}; cout << x[0][2] << endl; how does this output 4?

25th Oct 2017, 2:09 PM
raz roman k
raz roman k - avatar
3 Réponses
+ 4
First row, last col. When you're dealing with 2 dimensions, think of it as columns and rows. That'll help make sense of the data. Basically, [0] is that first row, and [2] is the last column. In this case, that's 4. Don't forget that array is 0-based index.
25th Oct 2017, 2:40 PM
AgentSmith
0
can I think of it as a two lines that cross each other? like how it is in the video game Zelda link to the past (creating a name).
25th Oct 2017, 4:12 PM
raz roman k
raz roman k - avatar
0
@Raz Yup, you can think of it like that. That's row/col. lol Horizontal/vertical lines intersecting. It's exactly like a grid.
25th Oct 2017, 5:31 PM
AgentSmith