Introduction
- homogenous data
- contiguous memory locations
- cache friendliness
- O(1) access
Types of Arrays
- Fixed size arrays ⇒ don't allow more items than current capacity
- Dynamic size arrays ⇒ automatically resize
Fixed Size Arrays
Note:
- In C/C++ fixed size arrays are allocated memory in two ways:
- stack segment allocation
int arr[100];
int arr[n];
int arr[] = {1,2,3,4,5};
- heap segment allocation
int *arr = new int[n];
- In java, arrays are always allocated in heap
int arr[] = new int[n];
Dynamic Size Arrays
- resize automatically
- in C++ it's called vector