+ 2

Two-dimensional arrays in C++

int x[2][3] = { {2, 3, 4}, {8, 9, 10} }; How do we get {2, 3, 4}, and {8, 9, 10}, how to calculate them and what they mean? {8, 9, 10}

29th Nov 2016, 7:30 PM
MysticMM
MysticMM - avatar
11 Respostas
+ 20
I'm not 100percent sure, but int x[2][3] means 2-member array, were every member has 3 member. So it is array of arrays))
29th Nov 2016, 7:53 PM
LyannaM
LyannaM - avatar
+ 1
it is not calculations. it's your declaration. I am saying 10 is stored there. have a look here https://www.programiz.com/c-programming/c-multi-dimensional-arrays
30th Nov 2016, 9:29 PM
Aliakbar Rezapour
Aliakbar Rezapour - avatar
+ 1
Ignoring the content for now, looking at the first part of the declaration ("int x[2][3]"), think of this as meaning two lines of three empty cardboard boxes: [ ] [ ] [ ] [ ] [ ] [ ] Since you declared them to be the integer type, you can only put whole numbers in, but if we had declared char x[2][3]; then we could place a letter in each box, e.g. x[0][0] = 'R'; resulting in [R] [ ] [ ] [ ] [ ] [ ] The numbers in the curly braces in your example are the initial values that you are placing in these boxes. You can do maths with the numbers you have in your array (e.g. x[1][1] = x[1][1] + x[1][2];), but the data structure you wrote is just for storing the data.
11th Mar 2017, 8:06 AM
Gavin Westwood
Gavin Westwood - avatar
0
when you assign x[a][b] , simply it would be a table with 'a' rows and 'b' columns. considering when defined index is the number of rows and columns but when you read/set starts from zero. in your example x[1][2]= 10
29th Nov 2016, 8:12 PM
Aliakbar Rezapour
Aliakbar Rezapour - avatar
0
And why is 10?
29th Nov 2016, 8:50 PM
MysticMM
MysticMM - avatar
0
because it's an item in the second row and third column. likewise: x[0][0]=2 , x[0][1]=3 , ...
29th Nov 2016, 9:16 PM
Aliakbar Rezapour
Aliakbar Rezapour - avatar
0
I still dont understant how do you calculate 10?
30th Nov 2016, 5:08 AM
MysticMM
MysticMM - avatar
0
Oh, you declare, thank you, well I didnt know that
1st Dec 2016, 4:52 AM
MysticMM
MysticMM - avatar
0
Think of it as a matrix with 2 rowsand three columns 0 represent the first row with three elements element 0 1 2 and 1 represent the second row with three columns again soo its a 2 by 3 dimensional array
29th Jan 2017, 6:37 AM
EMILLIO ITAI MARAMBO
EMILLIO ITAI MARAMBO - avatar
0
its a matrix of 3×3 there are three rows and three columns for example x [0][1] represents an element of first row and second column x [0][1]=3
16th Feb 2017, 9:23 AM
paras Juneja
paras Juneja - avatar
- 1
hi
30th Jul 2018, 8:10 AM
Harsh Sharma
Harsh Sharma - avatar