Rust program to print the ASCII value of a character

Here, we are going to learn how to print the ASCII value of a character in Rust programming language?
Submitted by Nidhi, on September 22, 2021

Problem Solution:

Here, we will create a character variable with some initial value. Then we will print the corresponding ASCII value of the character.

Program/Source Code:

The source code to print the ASCII value of a character is given below. The given program is compiled and executed successfully.

// Rust program to print the ASCII value
// of a character

fn main() {
    let mut ch:char='A';
    
    println!("ASCII value: {}",ch as u32);
    
    ch='&';
    println!("ASCII value: {}",ch as u32);

    ch='X';
    println!("ASCII value: {}",ch as u32);    
}

Output:

ASCII value: 65
ASCII value: 38
ASCII value: 88

Explanation:

Here, we created a character variable ch initialized with 'A', and then '&', 'X'. Then we printed the ASCCI value of the character.

Rust Basic Programs »



Related Programs



Comments and Discussions!

Load comments ↻





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