Ejercicios 3.1-4
This commit is contained in:
parent
e1bab0e4eb
commit
1e076842b6
|
@ -6,7 +6,7 @@
|
|||
|
||||
// Fix the error below with least amount of modification to the code
|
||||
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 !
|
||||
|
||||
assert_eq!(x, 5);
|
||||
|
@ -19,8 +19,8 @@ fn main() {
|
|||
|
||||
// Fill the blanks in the code to make it compile
|
||||
fn main() {
|
||||
let __ __ = 1;
|
||||
__ += 2;
|
||||
let mut x = 1;
|
||||
x += 2;
|
||||
|
||||
assert_eq!(x, 3);
|
||||
println!("Success!");
|
||||
|
@ -40,6 +40,7 @@ fn main() {
|
|||
let y: i32 = 5;
|
||||
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);
|
||||
}
|
||||
```
|
||||
|
@ -49,11 +50,12 @@ fn main() {
|
|||
|
||||
// Fix the error with the use of define_x
|
||||
fn main() {
|
||||
println!("{}, world", x);
|
||||
let x = define_x();
|
||||
println!("{}, world", x);
|
||||
}
|
||||
|
||||
fn define_x() {
|
||||
let x = "hello";
|
||||
fn define_x() -> String {
|
||||
String::from("hello")
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue