Home »
Rust »
Rust Programs
Rust program to convert an integer into character
Rust | Convert int to char: Given an integer, we have to convert it into the char.
Submitted by Nidhi, on October 08, 2021
Problem Solution:
In this program, we will create an integer variable then we will assign the value of the integer variable by converting it into a character variable using the "as" keyword.
Program/Source Code:
The source code to convert an integer into a character is given below. The given program is compiled and executed successfully.
// Rust program to convert an
// integer into character
fn main()
{
let mut intVar:u8 = 65;
let mut charVar:char;
charVar=intVar as char;
println!("Character is : {}",charVar);
}
Output:
Character is : A
Explanation:
Here, we created a variable intVar of the u8 type. Then we assigned the value of the intVar variable into the char variable using the "as" keyword. After that, we printed the result.
Rust Basic Programs »