Variables - Origian with types
This is the first version of the Variables page that included type defintions. Moving to a version that doesn't have that for now to see how it works
Keeping this here for reference.
Variables in Rust are created using the following structure:
- The
let
keyword - A name for the variable (e.g.
alfa
) - A
:
that acts as a separator - A data type
- The
=
sign - The value to bind to it (e.g.
7
) - A
;
the ends the definition
The data type from item 4 tells rust what
kind of content the variable can hold. For example,
it might be a number, or a letter, or full
sentence. We'll dig into data types in the
next chapter. We'll use i32
(which
stands for a number) until we get there.
Putting it all together we get this:
let alfa: i32 = 7;
Using that line in we can create
a full program that defines the alfa
variable then prints it out.
SOURCE CODE
fn main() {
let alfa: i32 = 7;
println!("The value is {}", alfa);
}