ADVERTISEMENT
ADVERTISEMENT

Rust program to initialize array elements with a default value

Rust | Array Example: Write a program to initialize array elements with a default value.
Submitted by Nidhi, on October 19, 2021

Problem Solution:

In this program, we will create two arrays and initialize them with default values. Then we will print the arrays.

Program/Source Code:

The source code to initialize array elements with a default value is given below. The given program is compiled and executed successfully.

// Rust program to initialize array 
// elements with a default value

fn main(){
   let arr1:[i32;5] = [-20;5];
   let arr2:[f32;5] = [-123.45;5];
   
   println!("Array1:\n{:?}",arr1);
   println!("Array2:\n{:?}",arr2);
}

Output:

Array1:
[-20, -20, -20, -20, -20]
Array2:
[-123.45, -123.45, -123.45, -123.45, -123.45]

Explanation:

Here, we created two arrays arr1, arr2, and initialized them with default values. Then we printed the arrays.

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.