+ 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}
11 odpowiedzi
+ 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))
+ 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
+ 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.
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
0
And why is 10?
0
because it's an item in the second row and third column. likewise:
x[0][0]=2 , x[0][1]=3 , ...
0
I still dont understant how do you calculate 10?
0
Oh, you declare, thank you, well I didnt know that
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
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
- 1
hi