memorias y struct

This commit is contained in:
2023-06-10 13:18:21 +02:00
parent 321e92f717
commit 140359f02d
5 changed files with 99 additions and 0 deletions

8
ejemplo03/Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "ejemplo03"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

16
ejemplo03/src/main.rs Normal file
View File

@@ -0,0 +1,16 @@
fn main() {
let x = 5u32;
let y: &u32;
{
let x_cuadrado = x * x;
let x_cubo = x_cuadrado * x;
// da un error por que la memoria es eliminada
// cuando es eliminado el scope
y = &(x_cubo + x_cuadrado + x);
};
let z = { 2 * x };
println!("x={}, y={}, z={}", z, y, z)
}