+ 1

Explain me Multidimensional Array Plx ??

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

14th Feb 2018, 10:25 AM
Yasir Khan
Yasir Khan - avatar
3 Respostas
+ 12
Multi dimensional array can be described as 'array of array' int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; //above statement is consist of three array to access first array we have to use index value 0 and to access first element of that array we have to use myArr[0][0] where 1st 0 index value for array selection and next 0 index value for first element of that array myArr[0][0]={1,2,3} myArr[0][1]={4} myArr[0][2]={5,6,7} myArr[0][2] = 42; // here 42 is assigned to first array third element so now the first array will be myArr[0][0]={1,2,42} int x = myArr[1][0]; // It will output 4 because second array is selected which first element is 4 so output is 4
14th Feb 2018, 10:54 AM
GAWEN STEASY
GAWEN STEASY - avatar
0
think of the array contents like: {1 2 3} {4} {5 6 7} now you could say myArr[ y ][ x ] refers to y=line and x=position in that line myArray[0][2] accesses line 0 @ position 2 -> {1 2 3} will become {1 2 42} int x = myArr[1][0] gets the value out of line 1, position 0 Just keep in mind that indexes start with 0 (instead of 1 like most humans count)
14th Feb 2018, 10:45 AM
Alex
Alex - avatar
0
thank you so much dearz
21st Feb 2018, 1:30 PM
Yasir Khan
Yasir Khan - avatar