9rustvariables

Understanding Variables in Rust

This guide introduces variables in Rust, explaining the let keyword and how to use it to declare mutable and immutable variables.


Variable Declaration in Rust

Variables in Rust are declared using the let keyword. To make a variable mutable, add mut:

// Declaring variables in Rust
let name = "Rust";    // Immutable
let mut age = 3;      // Mutable
age = 4;              // Allowed since it's mutable

Note: We aim to make learning easier by sharing top-quality tutorials, but please remember that tutorials may not be 100% accurate, as occasional mistakes can happen. Once you've mastered the language, we highly recommend consulting the official documentation to stay updated with the latest changes. If you spot any errors, please feel free to report them to help us improve.

top-home