Dynamic Memory Allocation
Unlike higher level program languages ( Like Python ), C does not normally allow you to change the size of a data structure (e.g. an array) after it has been defined
- Dynamic Memory Allocation allows you to avoid memory waste by allocating exactly the memory required
int *vector = (int *) malloc (sizeof(int)*array_size)
- Malloc (
): allocate ' ' bytes of memory : {C}'sizeof (int) * array_size'
is the size of the array in bytes- Malloc returns a void type pointer
{C}'(int *)'
typecasts this to{C}'int'