hello world and variables exploration
This commit is contained in:
24
variables/src/main.rs
Normal file
24
variables/src/main.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
//global variables use const or static NOT let and need a type indication
|
||||
const NAME : &str = "John";
|
||||
const HEX_NUM : &i32 = &0x01;
|
||||
|
||||
|
||||
|
||||
fn main() {
|
||||
// local variables dont need a type indication and are by default immutable
|
||||
let local_name = "Dough";
|
||||
let normal_int = 35;
|
||||
let hex_int = 0x35;
|
||||
let bin_int = 0b10101111;
|
||||
|
||||
//make them mutable by mut modifier
|
||||
let mut middle_name = "Levy";
|
||||
println!("temp middle name: {}",middle_name);
|
||||
middle_name = "Cena";
|
||||
|
||||
println!("name: {} {} {}",NAME,middle_name, local_name);
|
||||
println!("age: {}", normal_int);
|
||||
println!("hex: {}",hex_int);
|
||||
println!("const hex: {}",HEX_NUM);
|
||||
println!("binary: {}",bin_int);
|
||||
}
|
||||
Reference in New Issue
Block a user