284 views
0 votes
0 votes
how are addresses assigned to members in a structure and 2-dimensional arrays?

1 Answer

1 votes
1 votes
The memory allocation for the 2-dimensional array is contiguous. But entry in the memory correspond to Row major order or Column major order as 2-dimensional array can be viewed as Matrix.

2 Dimensional array: {{a11, a12}, {a21, a22}, {a31, a32}}
Matrix view : $\begin{bmatrix} a11 & a12 \\ a21 & a22 \\ a31 & a32 \end{bmatrix}$

If it is store as row major then memory will be look like as
$\begin{bmatrix} a11\\ a12\\ a21\\ a22\\ a31\\ a32 \end{bmatrix}$

If it is store column major order then memory will be look like as
$\begin{bmatrix} a11\\ a21\\ a31\\ a12\\ a22\\ a32 \end{bmatrix}$.

In Most programming language it is row major order. But it is implementation based.

For structure also memory allocation is contiguous.

No related questions found