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);
}
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.
Output:
Explanation:
Here, we created two arrays arr1, arr2, and initialized them with default values. Then we printed the arrays.
need an explanation for this answer? contact us directly to get an explanation for this answer