A dynamic array is an unpacked array whose size can be set or changed at run time, and hence is quite different from a static array where the size is pre-determined during declaration of the array. The default size of a dynamic array is zero until it is set by the new() constructor.


A dynamic array dimensions are specified by the empty square brackets [ ].

  [data_type] [identifier_name]  [];
  bit [7:0]   stack [];     // A dynamic array of 8-bit vector
  string     names [];     // A dynamic array that can contain strings 

The new() function is used to allocate a size for the array and initialize its elements if required.

  int   array [];       // A dynamic array that can hold elements of type int
  array = new [5];       // Create an array that can hold 10 elements
  array = '{1, 2, 3, 4, 5};   // Initialize the array

Login to your free account to read more ...

Was this article helpful ?