+ 1

What happened??

myArr[0][2] = 42; Hey , i donā€™t understand this line, so it means that the answer of myarr [0][2] is 42,?! How?!!

20th Feb 2018, 5:59 PM
Kiana
6 Answers
+ 4
What do you mean how? You very specifically assigned that value to it. myArr[0][2] = 42; ^That means assign the value of 42 to myArr[0][2]. That's also why your answer is 42. In regards to multi-dimensional arrays, think of it as a row/column system and that'll make it less confusing when dealing with them. Once you get into 3D+ arrays, I'd recommend writing down your structure. lol It can get really confusing beyond a simple 2D array, especially if dealing with large amounts of stored data.
20th Feb 2018, 6:04 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 4
whats the full question and in what language?
20th Feb 2018, 6:02 PM
Obbu
Obbu - avatar
+ 2
That's probably because the first item in your array (selected by [0]) is another array (let's call it ArrayB). So you are selecting ArrayB, and with [2] you select the third item of ArrayB (which was previously selected by [0]). So this means that myArr might be something like [[item1, item2, 42, more items...], more items...]
20th Feb 2018, 6:06 PM
Juca Navaz Reque
Juca Navaz Reque - avatar
+ 1
int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; myArr[0][2] = 42; int x = myArr[1][0]; // 4 Thanks guys , I understand why [1][0] is 4 but the thing is that what exactly myarr does in the answer of x ??
20th Feb 2018, 6:10 PM
Kiana
+ 1
which language is it?
20th Feb 2018, 6:15 PM
Juca Navaz Reque
Juca Navaz Reque - avatar
0
Itā€™s java
20th Feb 2018, 6:25 PM
Kiana