first commit

This commit is contained in:
Ashborn 2025-12-16 22:10:06 +05:45
commit a66604eb6c
52 changed files with 790 additions and 0 deletions

7
variables_mutability/Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "variables_mutability"
version = "0.1.0"

View file

@ -0,0 +1,6 @@
[package]
name = "variables_mutability"
version = "0.1.0"
edition = "2024"
[dependencies]

View file

@ -0,0 +1,39 @@
fn main() {
//variables by default is unchangable
//let is used to define the variables
let var1 = String::from("safal lama");
println!("default: {}", var1);
//mut is used to create a changable variable
let mut var2 = String::from("this is safal lama");
var2.push_str(". he is a huge fan of goku");
println!("mutable: {}", var2);
//shadowing is a process of redeclaring the variables
let var_shade = 1;
println!("{}", var_shade);
let var_shade = var_shade + 15;
println!("{}", var_shade);
let var_shade = "Safal lama"; //basically we can directly change the type of variable when shadowing
println!("{}", var_shade);
//constants are not changable and they have to be specified with type annotation
const KONST: i32 = 1;
println!("{}", KONST); // use caps for betterment
/*
[mutability and refrence]
only one mutable reference at a time or a multiple inmutable reference, but not both
*/
let mut str1 = String::from("kakarot");
let str2 = &mut str1; //only one mutable as rule
str2.push_str(", i am goku!");
println!("{}", str1);
//[can be multiple]
let strx = &str1;
println!("{}", strx);
/* [note]
The above code will work despite having mutable and inmutable both however, its about lifetime, cause one ends and other begins, if we didnt printed, then it wouldnt have worked.
*/
}