Q:

Rust program to create an array without specifying the type

belongs to collection: Rust Arrays Programs

0

In this program, we will create different types of arrays without specifying their type. Then we will print the array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to create an array without specifying type is given below. The given program is compiled and executed successfully.

// Rust program to create an array 
// without specifying type

fn main(){
   let arr1 = [5,10,15,20,25];
   let arr2 = [5.1,10.2,15.3,20.4,25.5];
   let arr3 = ["ABC","LMN","PQR","TUV","XYZ"];
  
   println!("Array1: {:?}",arr1);
   println!("Array2: {:?}",arr2);
   println!("Array3: {:?}",arr3);
}

Output:

Array1: [5, 10, 15, 20, 25]
Array2: [5.1, 10.2, 15.3, 20.4, 25.5]
Array3: ["ABC", "LMN", "PQR", "TUV", "XYZ"]

Explanation:

Here, we created three arrays arr1arr2, and arr3 with different data elements. After that, we printed the array elements.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Rust Arrays Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to find the length of an array... >>
<< Rust program to create a simple array...