11# Arrays and Slices
22
33An array is a collection of objects of the same type ` T ` , stored in contiguous
4- memory. Arrays are created using brackets ` [] ` , and their size , which is known
5- at compile time, is part of their type signature ` [T; size ] ` .
4+ memory. Arrays are created using brackets ` [] ` , and their length , which is known
5+ at compile time, is part of their type signature ` [T; length ] ` .
66
7- Slices are similar to arrays, but their size is not known at compile time.
7+ Slices are similar to arrays, but their length is not known at compile time.
88Instead, a slice is a two-word object, the first word is a pointer to the data,
99and the second word is the length of the slice. The word size is the same as
1010usize, determined by the processor architecture eg 64 bits on an x86-64.
@@ -31,8 +31,8 @@ fn main() {
3131 println!("first element of the array: {}", xs[0]);
3232 println!("second element of the array: {}", xs[1]);
3333
34- // `len` returns the size of the array
35- println!("array size : {}", xs.len());
34+ // `len` returns the count of elements in the array
35+ println!("number of elements in array : {}", xs.len());
3636
3737 // Arrays are stack allocated
3838 println!("array occupies {} bytes", mem::size_of_val(&xs));
0 commit comments