How do you determine the order in which an array is stored in C/C++?

1 Answers
Answered by suresh

How to Determine the Order of Array Storage in C/C++

How to Determine the Order of Array Storage in C/C++

In C and C++, arrays are stored in row-major order. This means that elements of a multi-dimensional array are stored in memory row by row.

The formula to determine the memory location of an element in a multi-dimensional array is:

address = base_address + ((row_size * row_index) + column_index) * element_size

Where:

  • base_address is the memory address of the first element of the array.
  • row_size is the total number of columns in a row.
  • row_index is the index of the row containing the element.
  • column_index is the index of the column within the row.
  • element_size is the size of each element in bytes.

By using this formula, you can determine the order in which elements are stored in memory in C and C++ arrays.

Answer for Question: How do you determine the order in which an array is stored in C/C++?