Dynamic array initialization

Hi,

When i initialise the dynamic array after allocating size, can it still take extra elements against the size. please see the following code
module tb;
// Create a dynamic array that can hold elements of type int
int array ;

initial begin
	// Create a size for the dynamic array -> size here is 5
  	// so that it can hold 5 values
array = new [5]; 			
  
  	// Initialize the array with five values
  array = '{31, 67, 10, 4, 99,100,101,2,2,3};      
 
  	// Loop through the array and print their values
  	foreach (array[i]) 
      $display ("array[%0d] = %0d", i, array[i]);
end

endmodule

In the above code, even though the size is restricted to 5, still the array takes other extra elements. the output for the above code is as below:
array[0] = 31
array[1] = 67
array[2] = 10
array[3] = 4
array[4] = 99
array[5] = 100
array[6] = 101
array[7] = 2
array[8] = 2
array[9] = 3

please let us know the reason behind it.

In reply to nishanthi.g:

Section 7.6 of the LRM discusses Array assignments:

If the target of the assignment is a queue or dynamic array, it shall be resized to have the same number of elements as the source expression and assignment shall then follow the same left-to-right element correspondence as previously described.

Since ‘array’ is dynamic, it will be resized to match the assignment. If you declared ‘array’ with a fixed size that was smaller than the assignment, you would have gotten an error.

In reply to cgales:

yes, got it !! thank you very much