+ 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

14th Jun 2018, 6:03 AM
Randeep Singh
Randeep Singh - avatar
5 Réponses
+ 3
I think it's equivalent to mat[1][0]
14th Jun 2018, 11:25 AM
Akshay Karande
+ 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
16th Jun 2018, 1:36 AM
Mauro Almeida
Mauro Almeida - avatar
+ 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.
14th Jun 2018, 7:06 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
The cout statement basically denotes this mat[1][0] which is equal to 3. and so the output you get is 3
15th Jun 2018, 11:19 AM
Abhinav Agarwal
Abhinav Agarwal - avatar
+ 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
14th Jun 2018, 1:45 PM
Rohit Ranbawale
Rohit Ranbawale - avatar