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.