An array is a group of variables having the same data type. It can be accessed using an index value.
An index is a memory address and the array value is stored at that address.
Array size is fixed throughout the simulation. Its value will be initialized with a ‘0’ value.
; // Declaration, and assignment Or int arr[3]; arr[0] = 5; arr[1] = 6; arr[2] = 7;
Example:
; initial begin foreach (array[i]) begin $display("array[%0d] = %0d", i, array[i]); end end endmodule
Output:
A multidimensional array is also known as an array of an array. In mathematics, we studied matrix, this can be understood as a multidimensional matrix.
, ', ', ', ', '>; // Declaration and assignment int arr[6][2]; // Declaration arr[0][0] = 1; // Assignment arr[0][1] = 100; arr[1][0] = 2; arr[1][1] = 200; arr[2][0] = 3; arr[2][1] = 300; arr[3][0] = 4; arr[3][1] = 400; arr[4][0] = 5; arr[4][1] = 500; arr[5][0] = 6; arr[5][1] = 600;
Example:
, ', ', ', ', '>; initial begin foreach (array[i,j]) begin $display("array[%0d][%0d] = %0d", i,j, array[i][j]); end end endmodule
Output:
Example:
, ', '>, ', ', '>, ', ', '> >; initial begin foreach (array[i,j, k]) begin $display("array[%0d][%0d][%0d] = %0d", i,j, k, array[i][j][k]); end end endmodule
Output:
The data object which does not have a specific range for bit/logic/reg is a scalar.
The data object which has a specific range for bit/logic/reg is a vector.
A packed array refers to the dimension mentioned before the variable or object name. This is also known as the vector width .
Memory allocation is always a continuous set of information that is accessed by an array index.
Example:
; initial begin foreach (array[i]) begin $display("array[%0h] = %0h", i, array[i]); end end endmodule
Output:
An unpacked array refers to the dimension mentioned after the variable or object name.
Memory allocation may or may not be a continuous set of information.
Example:
, ', ' >; initial begin foreach (array[i,j]) begin $display("array[%0d][%0d] = %0d", i, j, array[i][j]); end end endmodule
Output:
All arrays mentioned above are types of static arrays .
Example:
, ', ' >; initial begin foreach (array[i,j]) begin $display("array[%0h][%0h] = %0h", i, j, array[i][j]); end end endmodule
Output: