+ 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?!!
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.
+ 4
whats the full question and in what language?
+ 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...]
+ 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 ??
+ 1
which language is it?
0
Itâs java