primitive-type

Rust usize: pointer-width unsigned integer

`usize` stores nonnegative whole numbers. Its bit width matches the target pointer width, so the exact limits vary by target. A pointer-width nonnegative integer, used for array indices and collection lengths. Expected output: 18 Why: Rust arrays use zero-based indexing, so index 1 selects the second price. Common mistake: Do not rely on its width being 64 bits.

Formal Syntax & Structure

rust syntaxrust
let name: usize = integer_literal;

Working Example

Example Snippetrust
fn main() {    let prices = [12, 18, 25];    let index: usize = 1;    println!("{}", prices[index]);}
Rust Reference