cadenas y arrays
This commit is contained in:
7
arreglos/Cargo.lock
generated
Normal file
7
arreglos/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "arreglos"
|
||||
version = "0.1.0"
|
||||
8
arreglos/Cargo.toml
Normal file
8
arreglos/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "arreglos"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
21
arreglos/src/main.rs
Normal file
21
arreglos/src/main.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
fn main() {
|
||||
// definimos un array
|
||||
let mi_arreglo_3 = ["Lovecraft", "Poe", "Barker", "King"];
|
||||
// array mutable con 4 enteros
|
||||
let mut _mi_arreglo_2: [i32; 4] = [2, 4, 8, 16];
|
||||
// arreglo vacío tipo string
|
||||
let mut _arreglo_vacio: [&str; 0] = [];
|
||||
// crea el array con cuatro veces el 123
|
||||
let arreglo = [123; 4];
|
||||
// imprimimos para que no den error
|
||||
println!("{} {} {} ", mi_arreglo_3[1], _mi_arreglo_2[2], arreglo[3]);
|
||||
|
||||
let mut mi_arreglo: [&str; 4] = ["", "", "", ""];
|
||||
|
||||
mi_arreglo[0] = "Lovecraft";
|
||||
mi_arreglo[1] = "Poe";
|
||||
mi_arreglo[2] = "Barker";
|
||||
mi_arreglo[3] = "King";
|
||||
|
||||
println!("{}, {}, {}, {}", mi_arreglo[0], mi_arreglo[1], mi_arreglo[2], mi_arreglo[3]);
|
||||
}
|
||||
Reference in New Issue
Block a user