+ 1
Int x[2][3]={{2,3,4},{8,9,10}}; cout<<[0][2];how outputs 4 ?
C++
4 Answers
+ 5
2 3 4
8 9 10
Indexing starts from 0.
You have row 0 and row 1.
And column 0, 1, 2.
So [0][2] -> means row 0 and column 2.
Which is 4.
+ 3
what else did u expect?
it is 3rd element of first array
+ 2
Are you sure it was cout << [0][2]; ?
I got error message trying to run that snippet ...
However, it should output 4 if you wrote cout << x[0][2];
0
Int x[2][3]={{2,3,4},{8,9,10}}
Its like this:
2 3 4
8 9 10
You have 2 rows and 3 column.
First row index 0 : ( [0]--> 2 3 4) and the second row index 1 ([1]--> 8 9 10)
First column index 0: ( [0]--> 2 8) and the second column index 1 ([1]--> 3 9) and the third column index 2
([1]-->4 10)
First element in row 0 is x[0][0] = 2.
Second element in row 0 is x[0][1] = 3.
Third element in row 0 is x[0][2] = 4.
First element in row 1 is x[1][0] = 8.
Second element in row 1 is x[0][1] = 9.
Third element in row 1 is x[0][2] = 10.
X[0][2] means the third element in the first row, in this eg is 4.