hello world and variables exploration
This commit is contained in:
7
hello_world/Cargo.lock
generated
Normal file
7
hello_world/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "hello_world"
|
||||
version = "0.1.0"
|
||||
6
hello_world/Cargo.toml
Normal file
6
hello_world/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "hello_world"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
3
hello_world/src/main.rs
Normal file
3
hello_world/src/main.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
7
variables/Cargo.lock
generated
Normal file
7
variables/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
6
variables/Cargo.toml
Normal file
6
variables/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
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