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 Methods

SystemVerilog Data Types

How to use in-built methods of dynamic arrays

Open in IDE
testbench.v
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 5
		// so that it can hold 5 values
      	fruits = new [3];

		// Initialize the array with five 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.