+ 6

Can anyone explain following code

int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; myArr[0][2] = 42; int x = myArr[1][0]; // 4

24th Feb 2017, 11:09 AM
Mohit Kumar
Mohit Kumar - avatar
4 Respuestas
+ 9
That saves 42 to that element. At the initialization that element was set to 3.
24th Feb 2017, 12:33 PM
Tashi N
Tashi N - avatar
+ 7
Write it down as a table to understand it: 1 2 3 | a [0][0] a [0][1] a [0][2] 4 | a [1][0] 5 6 7 | a [2][0] a [2][1] a [2][2]
24th Feb 2017, 11:49 AM
Tashi N
Tashi N - avatar
+ 2
but why myArr[0][2] = 42;
24th Feb 2017, 12:24 PM
Mohit Kumar
Mohit Kumar - avatar
+ 1
thanks
24th Feb 2017, 12:21 PM
Mohit Kumar
Mohit Kumar - avatar