ProgrammingHard
A 2D array is stored in memory and read in column-major order by mistake in a C program. What is the main consequence?
- A. The sum is different because the cells are stored in a different order
- B. The loop visits memory with large strides, so it is slower than the row-major order though it gives the same sum
- C. The program fails to compile
- D. The array is transposed in memory
Correct answer: B. The loop visits memory with large strides, so it is slower than the row-major order though it gives the same sum
Both orders touch the same cells, so the answer is unchanged. Column-major access jumps across rows, which costs cache misses.
More C Programming questions
- The sum of i + j over all cells of a 3 x 3 grid with indices 0 to 2 is what?
- Which declaration creates a 3 x 3 identity matrix with C99 designators?
- For n = 10^5 cells in a 1D array viewed as a 316 x 317 grid, what is the total cell count?
- A matrix has R rows and C columns with R = 3 and C = 4 in a flat array of 12 ints. What flat index is cell (2, 3)?
- A square matrix is symmetric when a[i][j] equals a[j][i]. What is the time needed to test an n x n matrix for symmetry in C?
- A singly linked list is built by inserting 1, 2, 3 at the head. Then two nodes are popped from the head and their values printed. What is…