- Mastering Rust
- Rahul Sharma Vesa Kaihlavirta
- 142字
- 2021-07-02 13:35:17
Arrays
Arrays have a fixed length that can store items of the same type. They are denoted by [T, N], where T is any type and N is the number of elements in array. The size of the array cannot be a variable, but has to be a literal usize value:
// arrays.rs
fn main() {
let numbers: [u8; 10] = [1, 2, 3, 4, 5, 7, 8, 9, 10, 11];
let floats = [0.1f64, 0.2, 0.3];
println!("Number: {}", numbers[5]);
println!("Float: {}", floats[2]);
}
In the preceding code, we declared an array, numbers, which contains 10 elements for which we specified the type on the left. In the second array, floats, we specified the type as a suffix to the first item of the array, that is, 0.1f64. This is another way to specify types. Next, let's look at tuples.
推薦閱讀
- Java程序設計實戰教程
- Drupal 8 Blueprints
- Oracle從新手到高手
- 零基礎學Python數據分析(升級版)
- 軟件測試技術指南
- Hands-On Natural Language Processing with Python
- PySide 6/PyQt 6快速開發與實戰
- Learning OpenStack Networking(Neutron)(Second Edition)
- PHP+MySQL+Dreamweaver動態網站開發從入門到精通(第3版)
- Kivy Cookbook
- Cocos2d-x by Example:Beginner's Guide(Second Edition)
- C++從入門到精通(第6版)
- Building Slack Bots
- JavaEE架構與程序設計
- C/C++代碼調試的藝術(第2版)