To declare a float array in Rust, you can use array notation or the Vec type.
In this example,
floatArray
with predefined values using array notation.fn main() {
let float_array: [f32; 3] = [1.2, 3.4, 5.6];
println!("Float Array: {:?}", float_array);
}
Float Array: [1.2, 3.4, 5.6]
In this example,
empty_float_array
using the Vec type without any elements.fn main() {
let empty_float_array: Vec<f32> = Vec::new();
println!("Empty Float Array: {:?}", empty_float_array);
}
Empty Float Array: []
In this tutorial, we learned How to Declare a Float Array in Rust language with well detailed examples.