官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 洪洞县| 化州市| 霍山县| 马边| 鸡西市| 梁山县| 尼玛县| 南郑县| 鄯善县| 松阳县| 巨野县| 大冶市| 平阴县| 长兴县| 长宁县| 东兴市| 红安县| 赤水市| 中江县| 吴川市| 灯塔市| 南投市| 贵定县| 宜城市| 靖宇县| 咸阳市| 潮州市| 多伦县| 定安县| 宣汉县| 铜陵市| 辉南县| 罗甸县| 尚义县| 无棣县| 镇巴县| 陵川县| 蓝山县| 乳源| 北碚区| 美姑县|