fix: update slices
This commit is contained in:
parent
af26bbc8ea
commit
cc959387be
@ -74,6 +74,7 @@ fn find(nums: &[i32], target: i32) -> Option<usize> {
|
||||
fn main() {
|
||||
/* 初始化数组 */
|
||||
let arr: [i32; 5] = [0; 5];
|
||||
let slice: &[i32] = &[0; 5];
|
||||
print!("数组 arr = ");
|
||||
print_util::print_array(&arr);
|
||||
// 在 Rust 中,指定长度时([i32; 5])为数组
|
||||
|
@ -94,6 +94,7 @@
|
||||
```rust title="array.rs"
|
||||
/* 初始化数组 */
|
||||
let arr: [i32; 5] = [0; 5]; // [0, 0, 0, 0, 0]
|
||||
let slice: &[i32] = &[0; 5];
|
||||
// 在 Rust 中,指定长度时([i32; 5])为数组
|
||||
// 由于 Rust 的数组被设计为在编译期确定长度,因此只能使用常量来指定长度
|
||||
// Vector 是 Rust 一般情况下用作动态数组的类型
|
||||
|
@ -94,7 +94,7 @@ Arrays can be initialized in two ways depending on the needs: either without ini
|
||||
```rust title="array.rs"
|
||||
/* Initialize array */
|
||||
let arr: [i32; 5] = [0; 5]; // [0, 0, 0, 0, 0]
|
||||
let slice: &[i32] = [0; 5];
|
||||
let slice: &[i32] = &[0; 5];
|
||||
// In Rust, specifying the length ([i32; 5]) denotes an array, while not specifying it (&[i32]) denotes a slice.
|
||||
// Since Rust's arrays are designed to have compile-time fixed length, only constants can be used to specify the length.
|
||||
// Vectors are generally used as dynamic arrays in Rust.
|
||||
|
@ -74,6 +74,7 @@ fn find(nums: &[i32], target: i32) -> Option<usize> {
|
||||
fn main() {
|
||||
/* 初始化陣列 */
|
||||
let arr: [i32; 5] = [0; 5];
|
||||
let slice: &[i32] = &[0; 5];
|
||||
print!("陣列 arr = ");
|
||||
print_util::print_array(&arr);
|
||||
// 在 Rust 中,指定長度时([i32; 5])爲陣列,不指定長度時(&[i32])爲切片
|
||||
|
@ -94,7 +94,7 @@
|
||||
```rust title="array.rs"
|
||||
/* 初始化陣列 */
|
||||
let arr: [i32; 5] = [0; 5]; // [0, 0, 0, 0, 0]
|
||||
let slice: &[i32] = [0; 5];
|
||||
let slice: &[i32] = &[0; 5];
|
||||
// 在 Rust 中,指定長度时([i32; 5])爲陣列,不指定長度時(&[i32])爲切片
|
||||
// 由於 Rust 的陣列被設計為在編譯期確定長度,因此只能使用常數來指定長度
|
||||
// Vector 是 Rust 一般情況下用作動態陣列的類型
|
||||
|
Loading…
Reference in New Issue
Block a user