Array Basics

- 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 :
- When Random access of elements is needed [advantage over linked list]
- Can store multiple similar data types
- Disadvantages of array :
- Data needs to be of similar type
- Can't increase the size of array dynamically [disadvantage over linked list]
Comments
Post a Comment