Array in Rust is nothing but an object to store multiple values of the same data-type. Simply, an array is a homogeneous collection of values of the same data-type.
Pictorial Representation of an Array :
The above diagram is a representation of an array. This array holds integer type values.
An array is different from a variable in this way:
- A variable can store only one value at a time. But an array can store multiple values at a time.
- A variable stores the values in a random location, therefore making it difficult to retrieve the data when required. But, in the array, the data or values can be stored anywhere, but the retrieval can be done directly using the array index, which is much faster and feasible.
- A variable may not be feasible when multiple values of the same data type are to be stored, as different variables have to be declared and initialized in that case. But, in the array, the array name can be used to initialize different values, just with the help of the array index.