ADVERTISEMENT
ADVERTISEMENT

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

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

© https://www.includehelp.com some rights reserved.