Rust program to create different types of variables without specifying data types

Here, we are going to learn how to create different types of variables without specifying data types in Rust programming language?
Last Updated : September 19, 2021

Problem Statement

Here, we will create different types of variables without specifying data types and print them on the console 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 without specifying data types is given below. The given program is compiled and executed successfully.

// Rust program to create different types of variables 
// without specifying data types

fn main() {
	let var1=10;        //32-bit signed integer 
	let var2=30.12;     //32-bit floating point number
	let var3=true;      //Boolean value
	let var4='A';       //Character

	println!("Var1: {}",var1);
	println!("var2: {}",var2);
	println!("var3: {}",var3);
	println!("Var4: {}",var4);
}

Output

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

Explanation

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 »



Related Programs

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.