primitive-type
Rust array: store a fixed-size sequence of one type
An array stores a compile-time fixed number of elements of the same type. Its length is part of its type. Indexing begins at zero; safe indexing checks bounds. Expected output (not executed): 9 3 Why: Index 1 selects the second element, and the array length is three. Common mistake: An array cannot grow by pushing elements. Use Vec when length must change.
Formal Syntax & Structure
rust syntaxrust
[T; N]; [value1, value2, value3]Working Example
Example Snippetrust
fn main() { let scores: [u32; 3] = [7, 9, 8]; println!("{}", scores[1]); println!("{}", scores.len());}