Common terms in Rust

Printing Hello Rahul

Simply write the code mentioned below

fn main() { // from here the program starts and between two curly brackets whatever is written it contains execution part
    println!("Hello Rahul");    // printing Hello Rahul 
}
//if used  c language it sounds similar in terms of syntax

Variables

Simply store values or data or if you did not get it. Think variables are like containers which contains data. But once you put the data it cannot be changed. See with example

fn main(){
    let age = 5;
    println!("{x}");
    age = 10; // this line will give error because once defined we cannot change the value of variable
}
// if you want to change value use this way
fn main(){
    let mut age = 5; // explicitly defining that variables are mutable or can be changed
    println!("{x}");
    age = 10; // this line will give error because once defined we cannot change the value of variable
}

Constants

//Constant value remains constant and cannot be changed once defined. So it is immutable.
const age = 25 // done your job

Shadowing

Simply to outperform something. I guess for this you should read documentation
https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html
scroll down to the last one

0
Subscribe to my newsletter

Read articles from Rahul Srivastava directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rahul Srivastava
Rahul Srivastava