educative.io

Educative

Why is the first array called Dynamic Array?

int size = 10;

int [] dynamicArray = new int[size];

for(int i = 0; i < size; i++)
{
dynamicArray[i] = i;
}

versus the following array

int [] staticArray = new {1,2,3,4,5,6,7,8,9,10};

My question is how are the two array different. It is not clear to me that the first array is dynamic. In the chapter, the writer says that dynamic arrays do not have a predefined size, but the example above defines a size for the array and adds data elements with a for loop.

Hi @Carlos2,

In both cases, we need to allocate memory of some size. But in the static array, once we define the memory, we can not change it, and in the case of a dynamic array, we can re-allocate the memory according to our requirements.