diff --git a/guide/english/c/dynamic-memory-management/index.md b/guide/english/c/dynamic-memory-management/index.md index fb3ff05a8c..08854ef19f 100644 --- a/guide/english/c/dynamic-memory-management/index.md +++ b/guide/english/c/dynamic-memory-management/index.md @@ -1,34 +1,45 @@ --- 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 +Here's a simple example where we allocate an array, asking the user to choose the size. + ```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