+ 5

Multidimensional Arrays

Can someone explain these to me please. int[][] arr = new int[5][10] I understand the above but I dont understand what comes after that. When you iterate through the array to get certain values I get very confused. Please help, thx

10th Mar 2018, 12:07 AM
Tim Millar
Tim Millar - avatar
6 Réponses
+ 14
It's just the initialisation of multidimentionnal array. 5 and 10 is the length of array. For now, array are empty.
10th Mar 2018, 12:12 AM
MecyDev
MecyDev - avatar
+ 12
Yes. For iterate a multi array, need 2 or more for.
10th Mar 2018, 12:21 AM
MecyDev
MecyDev - avatar
+ 2
java is similar I guess, was looking for java answer but the loop process is the same just not the cout stuff. iam still confused but thx to all who helped thus far
10th Mar 2018, 3:48 AM
Tim Millar
Tim Millar - avatar
+ 1
think of it as a list inside a list. So, int[][]_2D_array = new int[m][n] would mean an (empty) array (_2D_array) of size m*n that will contain two lists/arrays. You'll need 2-loops (for loop is common) to access elements in _2D_array. The first tracks indices of first list ([m]) and the second loop handles that of [n]. You could print a matrix of M x N with this logic
10th Mar 2018, 7:41 AM
E_E Mopho
E_E Mopho - avatar