April 2026
Intermediate
631 pages
16h 20m
English
In this section, we’ll provide some practice questions to help reinforce your learning. The exercise questions cover almost all the concepts introduced in the chapter. Solutions to each exercise will follow in Section 2.6.
Correctly defining variablesFix the following code:
fn main(){ my_age = 40; println!("My age is: {}", my_age); // do not change this line }
Checking mutabilityCorrect the following code:
fn main(){ let x1 = 40; let x2 = x1; x2 = x1-2; // do not change this println!("x1 is: {} and x2 is: {}", x1,x2); // do not change this }
Mutability of variablesWithout executing the following code, determine if it will compile:
fn main() { let mut x1 = 40; let x2; x1 = x1 * 3; x2 = x1 - 2; println!("x1
Read now
Unlock full access