+ 6
Why output of this code is 3 ??
int mat[2][2]= {{1,2},{3,5}}; cout<<0[1[mat]]; plz anyone explain it. thanks in advance
5 Réponses
+ 3
I think it's equivalent to mat[1][0]
+ 3
mat[2][2]= {{1,2},{3,5}}
mat[0] = {1,2}
mat[1] = {3,5}
mat[0][0] = 1
mat[0][1] = 2
mat[1][0] = 3
mat[1][1] = 5
+ 2
On the first row you have a matrix with two rows and two columns. On the second when printing the result it says take the second row of the matrix with index 1 (start counting from 0)=> 3, 5 and then take the element with index 0 from that row which is 3.
+ 2
The cout statement basically denotes this
mat[1][0]
which is equal to 3.
and so the output you get is 3
+ 1
in example the matrix is [0] [1] cout ,we have to print output on screen is 0[1[mat]]; + +
[0]+ [1 3]
[1] +[2 5]
the position we have o find is [0,1] 0 is the row position and the 1 is column index
position then we found =3