Concept

Variable Mutability - Rust Programming

By default, variables in Rust are immutable, meaning their value cannot be changed once assigned. To allow a variable to be mutable, the keyword "mut" must be used when declaring the variable.

Immutable example:

let x = 5;

This declares a variable named "x" and assigns it the value of 5. The type of x is inferred by the compiler to be i32.

Mutable example:

let mut y = 10; y = 20;

This declares a mutable variable "y" with an initial value of 10 and then changes the value to 20.

0

1

Updated 2023-01-29

References


Tags

Object-Oriented Programming

Programming Language Paradigms

General programming languages

Computing Sciences