Q:

Rust program to print the ASCII value of a character

belongs to collection: Rust Basic Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Rust Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to demonstrate the arithmetic operato... >>
<< Rust program to read a float number from the user...