Views

Report Content

×
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:

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

Share and Join the Discussion

You need to be logged in to participate in this discussion.

×
×