Skip to main content

How is the memory address of an array element calculated?

The address of an array element is calculated arithmetically, using a formula that depends on:

  • the address of the start of the array,
  • the size of one element,
  • and the index of the needed element.

Formula

If:

  • base_address is the address of the first element of the array,
  • index is the number of the needed element (starting from 0),
  • size is the size of one element in bytes,

then:

[ \text{address} = \text{base_address} + (\text{index} \times \text{size}) ]


Example

Suppose:

  • array A starts at address 1000,
  • each element takes 4 bytes,
  • we need to find the address of A[3].

Substituting:

[ 1000 + (3 \times 4) = 1012 ]

The address of element A[3] is 1012.


Why this works

An array is stored in contiguous memory cells, with no "gaps". So each next element sits exactly size bytes further than the previous one. The computer doesn't need to "search" for an element, it simply performs this arithmetic calculation.


Important

  • It is exactly because of this scheme that index access in an array is O(1) (constant time).
  • This isn't possible with a linked list: there, elements sit in different places in memory, and you have to follow references.

Summary:

The address of an array element = start address + (index × element size). This makes an array one of the fastest structures for direct access to data.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.