Arrays are contiguous blocks in memory.
Arrays have a different measure of capacity and size. For example, an array can be of capacity eight, but of size 5, wasting 3 bytes (for an array of chars for example).
Review
Review why arrays in particular seems to have a space inefficiency thing where copying them needs to double the size. Have to do with Alignment perhaps?
Static
Static arrays, as the name implies are arrays whose size and capacity are known at compile time. In C and CPP they are declared by passing a number of elements in between brackets.
int arr[10];This can be extended to multi-dimensional arrays as follows:
int arr[10][10];However in the above case everything but the outermost array size must be known at compile time. (Not sure why)
Dynamically Allocated
Dynamic arrays are a contiguous chunk of memory whose size is unknown at compile time. As such, the above syntax for declaring an array cannot function properly. Instead, the size of the array is malloced as in the following example:
int* arr = malloc(x * sizeof(int));Where x is the number of elements to be malloced.
Note that this is different from dynamic arrays, which are resized automagically. In this case you would still need to resize the array manually or segfault.