Rust program to create different types of variables

Here, we are going to learn how to create different types of variables in Rust programming language?
Submitted by Nidhi, on September 19, 2021

Problem Solution:

In this program, we will create different types of variables and print them on the screen.

Note: By default, the variables are immutable, we cannot change the variables.

Program/Source Code:

The source code to create different types of variables is given below. The given program is compiled and executed successfully.

// Rust program to create 
// different types of variables

fn main() {
    let var1:i8     =10;        //8-bit signed integer 
    let var2:u16    =20;        //16-bit unsigned integer 
    let var3:f32    =30.12;     //32-bit floating point number
    let var4:bool   =true;      //Boolean value
    let var5:char   ='A';       //Character
    println!("Var1: {}",var1);
    println!("var2: {}",var2);
    println!("var3: {}",var3);
    println!("Var4: {}",var4);
    println!("Var5: {}",var5);


Var1: 10
var2: 20
var3: 30.12
Var4: true
Var5: A


In the main() function, we created 5 different types of variables using the let keyword. Then we printed the value of variables using println!() macro on the console screen.

Rust Basic Programs »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.