Concept Flow - Scalar data types
Start
Declare variable with scalar type
Assign value
Use variable in code
Program runs with scalar data
End
This flow shows how scalar data types are declared, assigned, and used in Rust programs.
fn main() {
let x: i32 = 10;
let y: f64 = 3.14;
let z: bool = true;
println!("x = {}, y = {}, z = {}", x, y, z);
}| Step | Action | Variable | Type | Value | Output |
|---|---|---|---|---|---|
| 1 | Declare variable x | x | i32 | uninitialized | |
| 2 | Assign 10 to x | x | i32 | 10 | |
| 3 | Declare variable y | y | f64 | uninitialized | |
| 4 | Assign 3.14 to y | y | f64 | 3.14 | |
| 5 | Declare variable z | z | bool | uninitialized | |
| 6 | Assign true to z | z | bool | true | |
| 7 | Print values | x,y,z | i32,f64,bool | 10,3.14,true | x = 10, y = 3.14, z = true |
| Variable | Start | After Step 2 | After Step 4 | After Step 6 | Final |
|---|---|---|---|---|---|
| x | uninitialized | 10 | 10 | 10 | 10 |
| y | uninitialized | uninitialized | 3.14 | 3.14 | 3.14 |
| z | uninitialized | uninitialized | uninitialized | true | true |
Scalar data types hold single values like numbers or true/false. Common types: i32 (integer), f64 (float), bool (true/false). Declare with let and specify type or let Rust infer it. Assign values before use. Use println! to display values. Rust enforces type safety and initialization.