To declare an integer array in Rust, you can use array notation or the Vec container.
In this example,
numbers
with predefined values using array notation.fn main() {
let numbers = [1, 2, 3, 4, 5];
println!("Integer Array: {:?}", numbers);
}
Integer Array: [1, 2, 3, 4, 5]
In this example,
empty_array
using the Vec container.fn main() {
let empty_array: Vec<i32> = Vec::new();
println!("Empty Integer Array: {:?}", empty_array);
}
Empty Integer Array: []
In this tutorial, we learned How to Declare an Integer Array in Rust language with well detailed examples.