Array Basics

Pointers and 1-D arrays - OverIQ.com
  • Size of the array is fixed and can't be modified during runtime
  • Arrays store data of specified type only
  • Every cell has a unique index
  • The index starts at 0. 
  • Array elements are stored at contiguous memory locations in the array. Elements of all array types including linear, 2D, 3D, etc are stored in linear contiguous locations in memory.
  • Suppose we want to go to a[6] i.e. seventh element and not 6th element, the computation is done internally as 0+6 i.e 6 elements after the first element, hence we get the seventh element.

refToArray[x102] -------->[0][0][0][0]
                                            here we get to the first element as x102 + 0
                                                                to the second element as x102 + 1  and so on

Here x102 is the address of the first element of the array

  • Advantages of array :
  1. When Random access of elements is needed [advantage over linked list]
  2. Can store multiple similar data types
  • Disadvantages of array :
  1. Data needs to be of similar type
  2. Can't increase the size of array dynamically [disadvantage over linked list]

Comments

Popular posts from this blog

Quick Sort

Disjoint Set - Implemented Using Arrays

Graph Traversal Code - BFS on Graph represented using Adjacency Matrix