mirror of
https://github.com/mainmatter/100-exercises-to-learn-rust
synced 2024-12-25 21:58:26 +01:00
doc: update book 06_01_arrays (#195)
This commit is contained in:
parent
ab1eb5d80c
commit
51cad6bdfe
1 changed files with 9 additions and 0 deletions
|
@ -21,6 +21,15 @@ let numbers: [u32; 3] = [1, 2, 3];
|
|||
This creates an array of 3 integers, initialized with the values `1`, `2`, and `3`.\
|
||||
The type of the array is `[u32; 3]`, which reads as "an array of `u32`s with a length of 3".
|
||||
|
||||
If all array elements are the same, you can use a shorter syntax to initialize it:
|
||||
|
||||
```rust
|
||||
// [ <value> ; <number of elements> ]
|
||||
let numbers: [u32; 3] = [1; 3];
|
||||
```
|
||||
|
||||
`[1; 3]` creates an array of three elements, all equal to `1`.
|
||||
|
||||
### Accessing elements
|
||||
|
||||
You can access elements of an array using square brackets:
|
||||
|
|
Loading…
Reference in a new issue