Complete the code to declare an immutable variable named x with value 5.
let [1] = 5;
mut makes the variable mutable, which is not what we want.var is not valid syntax in Rust.In Rust, variables are immutable by default. To declare an immutable variable named x, just write let x = 5;.
Complete the code to print the value of the immutable variable y.
let y = 10; println!("[1]", y);
%d is not valid in Rust's println! macro.To print a variable's value in Rust, use println!("{}", variable);. The curly braces {} are placeholders for the variable.
Fix the error in the code by completing the blank to make the variable z immutable.
let [1] = 20; z = 30; // This line causes an error
mut to fix the error changes the variable to mutable, which is not the goal.var is invalid syntax in Rust.The variable z is declared immutable by let z = 20;. Trying to assign a new value to z causes an error because immutable variables cannot be changed.
Fill both blanks to declare an immutable variable a with value 15 and print it.
let [1] = 15; println!("[2]", a);
mut a makes the variable mutable, which is not needed."a" prints the letter 'a', not the variable's value.Declare a as immutable with let a = 15;. To print its value, use println!("{}", a);.
Fill all three blanks to declare an immutable variable name with value "Rust", then print it with a message.
let [1] = [2]; println!("Hello, [3]!");
mut name makes the variable mutable.println! causes errors.Declare name as immutable with let name = "Rust";. To print it inside a message, use println!("Hello, {}!", name);.