Ejercicios 3.1-4

This commit is contained in:
perro tuerto 2023-03-20 11:01:58 -07:00
parent e1bab0e4eb
commit 1e076842b6
1 changed files with 8 additions and 6 deletions

View File

@ -6,7 +6,7 @@
// Fix the error below with least amount of modification to the code // Fix the error below with least amount of modification to the code
fn main() { fn main() {
let x: i32; // Uninitialized but used, ERROR ! let x: i32 = 5; // Uninitialized but used, ERROR !
let y: i32; // Uninitialized but also unused, only a Warning ! let y: i32; // Uninitialized but also unused, only a Warning !
assert_eq!(x, 5); assert_eq!(x, 5);
@ -19,8 +19,8 @@ fn main() {
// Fill the blanks in the code to make it compile // Fill the blanks in the code to make it compile
fn main() { fn main() {
let __ __ = 1; let mut x = 1;
__ += 2; x += 2;
assert_eq!(x, 3); assert_eq!(x, 3);
println!("Success!"); println!("Success!");
@ -40,6 +40,7 @@ fn main() {
let y: i32 = 5; let y: i32 = 5;
println!("The value of x is {} and value of y is {}", x, y); println!("The value of x is {} and value of y is {}", x, y);
} }
let y: i32 = 5;
println!("The value of x is {} and value of y is {}", x, y); println!("The value of x is {} and value of y is {}", x, y);
} }
``` ```
@ -49,11 +50,12 @@ fn main() {
// Fix the error with the use of define_x // Fix the error with the use of define_x
fn main() { fn main() {
println!("{}, world", x); let x = define_x();
println!("{}, world", x);
} }
fn define_x() { fn define_x() -> String {
let x = "hello"; String::from("hello")
} }
``` ```