125k views
1 vote
Consider

int[][] a = {{1,2},{3,4,5}};
int[] b = a[1];
b[0] = 10;

What are the indices i and j of the array element a[i][j] that is equal to 10 after the above code fragment is executed?

1 Answer

4 votes

Answer:

i = 1

j = 0

a[1][0] = 10

Step-by-step explanation:

First define a matrix a that correspond to

[1,2]

[3,4,5]

Later the variable b point to the a[1]

b = [3,4,5]

Later change the value 0 of b

b = [10,4,5]

The final matrix is

0 1 2

0 [ 1 2 ]

1 [ 10 4 5 ]

And then the 10 value is located in a[1][0]

User Saafo
by
5.4k points