Please i need help on multidimensional arrays in c++, it is a challenge to me, | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please i need help on multidimensional arrays in c++, it is a challenge to me,

Like this one int x[2][3] = { {2, 3, 4}, // 1st row {8, 9, 10} // 2nd row }; Please why do they skip 5,6,7 and land at 8,9,10? And what do they mean by 2D,3D shapes ?

9th Mar 2019, 1:03 PM
Agofack
Agofack - avatar
6 Answers
+ 6
Hi Agofack, Ever used a spreadsheet application like MS Excel? we can think of a worksheet when it comes to 2D arrays, worksheets consist of rows and columns. The difference to note here in a language such as C++, arrays must contain data of a certain type, that is, we cannot mix different types of data in an array. Q: Why they skip some values? A: We are free to store any data at a certain cell, as long as data type is correct. We can even change the values as we see fit. Q: What do they mean by 2D, 3D? A: The 'D' letter following the number describes the number of dimensions the said array is allocated: ● 1D arrays consist of one row with multiple columns. ● 2D arrays consist of multiple rows with multiple columns. A worksheet of rows and columns can be used to picture this. ● 3D arrays consist of rows and columns, where each columns themselves are arrays. A Rubik cube can be used to picture this, it has height (rows), (width) columns, and each column builds the cube's volume. Hth, cmiiw
10th Mar 2019, 7:25 AM
Ipang
+ 1
Ipang Oh thanks
10th Mar 2019, 10:22 AM
Agofack
Agofack - avatar
0
you can think of multidimensional arrays as a table with rows and columns. those numbers (8,9,10)can be anything you want. the example you provided has 3 rows and 4 columns. so there should be more data in it. here is a visual table for your array | x[0] [0] ¦ x[0] [1] ¦ x[0] [2] ¦ x[0] [3] | _________ _______ __________ ________ | x[1] [0] ¦ x[1] [1] ¦ x[1] [2] ¦ x[1] [3] | _________ _______ _________ ______ | x[2] [0] ¦ x[2] [1] ¦ x[2] [2] ¦ x[3] [3] | 2D shapes are like a rectangle, a square.... 3D shapes are cubes, prism..... things that have a height, width and length.
9th Mar 2019, 1:26 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
bahha thanks but this still not clear to me 3rows and 4columns, i taught it is 2rows ,3 column, look at it int x[2][3]=, please how come is it 3rows and 4 columns? thanks
9th Mar 2019, 1:36 PM
Agofack
Agofack - avatar
0
Agofack because in arrays the index start at 0. look at the table. don't confuse the array index and the value they can hold. for example you can write: x[0] [0] = 5; each place on the table can have its own value.
9th Mar 2019, 1:43 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
bahha ohh thanks very much my worries are all gone thanks once more
9th Mar 2019, 2:03 PM
Agofack
Agofack - avatar