Skip to content

Commit bf4e4e3

Browse files
authored
Change array initialization syntax (#2662)
1 parent 0134c25 commit bf4e4e3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/tuples-and-arrays/arrays.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ minutes: 5
88

99
```rust,editable
1010
fn main() {
11-
let mut a: [i8; 10] = [42; 10];
12-
a[5] = 0;
11+
let mut a: [i8; 5] = [5, 4, 3, 2, 1];
12+
a[2] = 0;
1313
println!("a: {a:?}");
1414
}
1515
```
1616

1717
<details>
1818

19+
- Arrays can also be initialized using the shorthand syntax, e.g. `[0; 1024]`.
20+
This can be useful when you want to initialize all elements to the same value,
21+
or if you have a large array that would be hard to initialize manually.
22+
1923
- A value of the array type `[T; N]` holds `N` (a compile-time constant)
2024
elements of the same type `T`. Note that the length of the array is _part of
2125
its type_, which means that `[u8; 3]` and `[u8; 4]` are considered two

0 commit comments

Comments
 (0)