--- title: Dynamic Memory Management --- # Dynamic Memory Management Sometimes you will need to allocate memory spaces in the heap also known as the dynamic memory. This is particulary useful when you do not know during compile time how large a data structure (like an array) will be. ## An Example Here's a simple example where we allocate an array asking the user to choose the dimension ```C #include #include int main(void) { int arrayDimension,i; int* arrayPointer; printf("Please insert the array dimension:"); scanf("%d",&arrayDimension); arrayPointer = (int*)malloc(sizeof(int)*arrayDimension); if(arrayPointer == NULL){ printf("Error allocating memory!"); return -1; } for(i=0;i