Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Dynamic Array Example

SystemVerilog Arrays

Runnable example from the SystemVerilog Dynamic Array tutorial (Dynamic Array Example)

Open in IDE
testbench.sv
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};
  
		// Loop through the array and print their values
		foreach (array[i])
			$display ("array[%0d] = %0d", i, array[i]);
	end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.