Rust program to create an array without specifying the type

Rust | Array Example: Write a program to create an array without specifying the type.
Submitted by Nidhi, on October 19, 2021

Problem Solution:

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

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 arr1, arr2, and arr3 with different data elements. After that, we printed the array elements.

Rust Arrays Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.