Skip to content

Commit 51cad6b

Browse files
authored
doc: update book 06_01_arrays (#195)
1 parent ab1eb5d commit 51cad6b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

book/src/06_ticket_management/01_arrays.md

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ let numbers: [u32; 3] = [1, 2, 3];
2121
This creates an array of 3 integers, initialized with the values `1`, `2`, and `3`.\
2222
The type of the array is `[u32; 3]`, which reads as "an array of `u32`s with a length of 3".
2323

24+
If all array elements are the same, you can use a shorter syntax to initialize it:
25+
26+
```rust
27+
// [ <value> ; <number of elements> ]
28+
let numbers: [u32; 3] = [1; 3];
29+
```
30+
31+
`[1; 3]` creates an array of three elements, all equal to `1`.
32+
2433
### Accessing elements
2534

2635
You can access elements of an array using square brackets:

0 commit comments

Comments
 (0)