April 2026
Intermediate
631 pages
16h 20m
English
This section provides the code solutions for the practice exercises in Section 2.5. The code is largely self-explanatory; however, we have included comments and additional explanations wherever necessary to enhance understanding.
Correctly defining variables
fn main(){ let my_age = 40; println!("My age is: {}", my_age); }
Checking mutability
fn main(){ let x1 = 40; let mut x2 = x1; x2 = x1-2; println!("x1 is: {} and x2 is: {}", x1,x2);}/* Note: There will be a warning when you execute that the value of x2 has been immediately overwritten before being read. You may just ignore it otherwise add the line #![ allow(unused)] at the top before the fn main() if you do want to see the warning. */
Mutability of variables
fnRead now
Unlock full access