Arrays
An array is used to represent the collection of items. These items should be of same data types such as a list of marks obtained by a student or the names of members of a family. The items of an array must belong to a same data type.
In V, arrays can hold elements of similar data types that comprise primitive types or advanced types such as structs. By default, when an array is created, the memory allocation happens on the heap. You can create an array of a fixed size whose memory is allocated within the stack. Arrays can have more than one dimension. By default, arrays in V are immutable. Mutable arrays can be declared using the mut
keyword.
The following is the syntax to declare an array:
arr := [VAL_1, VAL_2, .. VAL_N]
The preceding syntax demonstrates the declaration of a one-dimensional immutable array. The variable name is arr
followed by the :=
symbol. To the right of the statement, we have a list of values that must be of a similar data type. The values of...