Multiple choice

int i,j; int ctr = 0; int myArray[2][3]; for (i=0; i<3; i++) for (j=0; j<2; j++) { myArray[j][i] = ctr; ++ctr; } What is the value of myArray[1][2]; in the sample code?

  1. 1

  2. 2

  3. 3

  4. 4

  5. 5

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

The loops store ctr values in transposed index order: myArray[j][i] where i is outer (0-2) and j is inner (0-1). After all iterations: myArray[0]=[0,2,4], myArray[1]=[1,3,5]. Therefore myArray[1][2] equals 5. The 2x3 array is filled column-wise due to swapped indices.