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 string
	string 	fruits [];

	initial begin
		// Create a size for the dynamic array -> size here is 3
		// so that it can hold 3 values
      	fruits = new [3];
  
		// Initialize the array with three values
      	fruits = '{"apple", "orange", "mango"};
  
      	// Print size of the dynamic array
		$display ("fruits.size() = %0d", fruits.size());
  
		// Empty the dynamic array by deleting all items
		fruits.delete();
		$display ("fruits.size() = %0d", fruits.size());
	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.