+ 1
Multidimensional Arrays
Multidimensional Arrays int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; myArr[0][2] = 42; int x = myArr[1][0]; // 4 I don't understand this line : myArr[0][2] = 42; and why output 4 ?
2 Respostas
+ 6
imagine it in this format:
(the numbers without | | around them are indexes)
0 1 2
0 |1|2|3|
1 |4|
2 |5|6|7|
so myArr[0][2]=42 basically accesses and changes the value inside row 2, column 0, from 3 to 42
so after that assignment the array will look like this:
0 1 2
0 |1|2|42|
1 |4|
2 |5|6|7|
and int x = myArr[1][0] will assign the value that is inside row 1, column 0 into the x variable.
+ 1
@Burey thank you so much!!