ProgrammingModerate
Row-major storage of int a[4][5] means a[i][j] is at flat index i * 5 + j. What flat index holds a[3][2]?
- A. 16
- B. 18
- C. 13
- D. 17
Correct answer: D. 17
3 * 5 + 2 = 17. Using 4 as the row length (the first dimension) would give 14 instead, which is the common mistake.
More C Programming questions
- int a[2][3] with a pointer p = &a[0][0]. Which expression gives the number of elements between a[0][0] and a[1][2]?
- The sum of the elements of a[i][j] = i j over the 4 x 4 matrix equals what?
- Which statement about matrix multiplication in C is correct for an m x k matrix times a k x n matrix?
- Sum of a 2 x 2 window of m[i][j] = i + j starting at (1,1) in a 4 x 4 grid, i.e. m[1][1] + m[1][2] + m[2][1] + m[2][2]. What is the value?
- In a 2D array with int a[5][5], what is the total number of bytes in one row when int is 4 bytes?
- What is the most efficient way to check whether an n x n matrix is symmetric in O(n^2)?