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?

  1. A. The sum is different because the cells are stored in a different order
  2. B. The loop visits memory with large strides, so it is slower than the row-major order though it gives the same sum
  3. C. The program fails to compile
  4. 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

Exams that ask this topic