ADVERTISEMENT
ADVERTISEMENT

Rust program to find the length of an array

Rust | Array Example: Write a program to find the length of an array.
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 find the length of the array using the len() function and print the result.

Program/Source Code:

The source code to find the length of an array is given below. The given program is compiled and executed successfully.

// Rust program to find the 
// length of an array

fn main(){
   let arr1 = [5,10,15];
   let arr2 = [5.1,10.2,15.3,20.4];
   let arr3 = ["ABC","LMN","PQR","TUV","XYZ"];
   
   println!("Length of arr1: {}",arr1.len());
   println!("Length of arr2: {}",arr2.len());
   println!("Length of arr3: {}",arr3.len());
}

Output:

Length of arr1: 3
Length of arr2: 4
Length of arr3: 5

Explanation:

Here, we created three arrays arr1, arr2, and arr3 with different data elements. Then we found the length of the array and printed the result.

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.