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.
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.
Output:
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