**The 'base address' of a 2D array is the starting point of the array, it may be the given address to calculate the element’s address of a 2D array. An array is a data structure that is used to store big data for processing. Multiple data processing operations can be applied to an array. In the article, we will look at the details of the 2D array and the process of calculation of an element’s address with the help of ‘the base address of a two dimensional array’.**

##### Photo by Tatiana Syrikova

**Table of Contents: #**

**What is an Array?**

A **data structure** with a collection of elements is called an array. These components are typical of all the same data types, like an integer or string. Computer applications frequently utilize arrays to organize data so that a related set of values may be quickly searched for or sorted.

**Known types of the arrays.**

**Single-dimensional** arrays, **two-dimensional** arrays, and **multidimensional** arrays are the three different types or kinds of arrays.

**Single-dimensional array.**

An example of a linear array is a single dimension array (also known as a **one-dimensional array**). Its components are accessed via a single subscript, which can either be a row or column index. Here I will take the example of C language declaration

`int anArrayName[10];`

as an illustration, which specifies a single-dimensional array of ten numbers. A single-dimensional array is a structured group of elements that may be accessed separately by designating a single index value for each element's position. The single-dimensional array is also called an **array of elements.**

**Two-dimensional array.**

You can think of a two-dimensional array as a matrix with rows and columns. A two-dimensional array can be declared using the following general syntax:

`int myArray[10][10]; // C language declaration example.`

A collection of different one-dimensional arrays makes up a two-dimensional array. To develop a data structure that resembles a relational database, a 2D array is made. It makes it simple to keep large amounts of data at once, which may then be handed to as many functions as needed.

**Multi-dimensional array.**

An array of arrays that contains homogeneous data in tabular form is what is referred to as a multi-dimensional array. An array with more than one dimension (a two-dimensional array is also a multi-dimensional array) is referred to as a multi-dimensional array. It is an array of arrays and a multi-level array. The 2D or 3D array, often known as a two-dimensional or three-dimensional array, is the most basic multi-dimensional array. Technically speaking, as you will see in the code, it is an array of arrays. A 2D array is also known as a matrix, a table with rows and columns, or a 2D array.

`Int myArry[10][10][10]; // //C language declaration example of a three-dimensional array`

**What is the base address of an array?**

The base address is the starting address of the element of an array. It is used to calculate the element's address, if it is not specified to calculate the address then assume it 0. So in simple words, I can say the base address of any array is the starting address if not specified.

**How do arrays stores in memory?**

Understanding the storage procedure of an array in memory is simple, arrays are stored two ways one is row-major and the second one is column-major.

**Row-major order.**

The rows of the 2D array are continuously kept in memory using row-major ordering. The graphic depicts an array, and the memory allocation according to row-major order is displayed as follows.

For instance: We have a 2D array that has 3 rows and 3 columns.

`Int myArray[3][3];`

(0,0) |
(0,1) |
(0,2) |
(1,0) |
(1,1) |
(1,2) |
(2,0) |
(2,1) |
(2,2) |

It will be stored like a lenient row in the memory.

**Column major order.**

All the columns of the 2D array are continuously kept in memory following the column-major ordering. The array that is seen in the above figure has the following memory allocation:

(0,0) (1,0) (2,0) (0,1) (1,1) (2,1) (2,0) (2,1) (2,2)It is also stored in the same way by column.

**How to calculate an element’s address with the help of the base address of a 2D array?**

Two separate formulas are used to determine the address of a random element in a two-dimensional array since there are two different methods for storing the array in memory.

**Employing for Row-major order.**

Address of an element a[i][j] of the array stored in row-major order is determined as if the array is declared by a[m][n] where m is the number of rows and n is the number of columns.

`Address(a[i][j]) = BA. + I `* n + j) * size.

where BA. denotes the base address or the location of the array's first element, if not specified then assume it as a[0][0].

`a[10...30, 55...75], base address of the array (BA) = 0, size of an element = 4 bytes. `

Find the location of a[15][68].

`Address(a[15][68]) = 0 + ((15 - 10) x (68 - 55 + 1) + (68 - 55)) x 4`

= (5 x 14 + 13) x 4

= 83 x 4

= 332 answer

**Employing** **column-major order.**

Address of an element a[i][j] of the array stored in row-major order is determined as if the array is declared by a[m][n] where m is the number of rows and n is the number of columns.

`Address(a[i][j]) = ((j`*m)+i)*Size + BA

where BA is the array's base address.

` A [-5 ... +20][20 ... 70], BA = 1020, Size of element = 8 bytes. Find the location of a[0][30]. `

Address [A[0][30]) = ((30-20) x 24 + 5) x 8 + 1020 = 245 x 8 + 1020 = 2980 bytes

**The Conclusion**

I hope after reading this article anyone can understand what the array is, how many types of arrays has, what is the base address and how to calculate the address of an element with the base address.