ADVERTISEMENT
ADVERTISEMENT

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 »



ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.