Dynamic Array


Dynamic Array

The dynamic array is exactly the same as the regular arrays, but its size is adjusted during the operating period of the system. DynamArray elements occupy a compact memory block.

Once the array is created, its size cannot be changed. However, the dynamic array is different. The same flexible members can expand their size even after it has been completed.

During the construction of the same component, it is given a predetermined amount of memory. This is not the case with the flexible system as it increases the memory size by a specific feature where necessary.

The initial size of the array and its growth factor determine its functionality.

  • If the same array has a smaller size and a smaller growth factor, then it will continue to reproduce memory more often. This will reduce the performance of the array.
  • If the same array has a larger size and a larger growth factor, then it will have a larger piece of unused memory. Because of this, resizing operations may take longer. This will reduce the performance of the array.

The new Keyword

In C ++, we can create similar dynamic arrays using a new keyword. The number of items to be provided is specified between the pairs of square brackets. The genre name must precede this. The number of requested items will be shared.

Syntax:

The syntax of the new keyword is as follows :

  • pointer_variable = new data_type;