0

Why is this array's row index empty?

Given this array: int arr[][2]={{3,2},{4,5},{9,7}}, What is the value of the following? arr[2][1]; __________________________________________________________________________ So it means there are however many rows (that's why it's empty []), and two columns! 3 2 4 5 9 7 (I see the row index is left empty in general, since the computer can figure out how many rows there are. It can't tell how many columns there are, so we have to tell it.)

6th Jun 2017, 5:55 AM
gorgamin
gorgamin - avatar
4 odpowiedzi
+ 4
Error. You need to separate each array with a comma like this: {{3,2} , {x,y}...; ^^ Then the output should be 7. {3,2} Is the array at the 0th index. Or: [0][] {4,5} Is the array at the first index Or: [1][] {9,7} Is the array at the second index Or: [2][] So what is [2][1] Well [2][]: { 9, 7 } index: 0, 1 1 is the indexOf 7. So 7 is the answer.
5th Jun 2017, 10:58 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
the compiler divide the values by the last indexs, the first index is the result of that. int Array[][5] = {1,2,3,4,5, 6,7,8,9,10}; //Rows size is 2 (10/5=2) int Array[][2][3] = {1,2,3, 4,5,6, 7,8,9 ,10,11,12}; //First index size is 2 (12/(2*3)=12/6=2)
6th Jun 2017, 1:42 AM
Andrés04_ve
Andrés04_ve - avatar
0
well, i'm not sure if the compiler does it, but something do it
6th Jun 2017, 1:43 AM
Andrés04_ve
Andrés04_ve - avatar
0
Oops, I edited it... Thanks!
6th Jun 2017, 5:54 AM
gorgamin
gorgamin - avatar