GitHub

Practice

Practice - 007

A program to explain type casting

fn main() {
practice7()
}
fn practice7() {
let a = 2;
let b = 5;
println!("Without type casting, a / b = {}", (a as f32 / b as f32));
println!("With type casting, a / b = {}", (a / b));
}

Result

Without type casting, a / b = 0.4
With type casting, a / b = 0
Previous
Practice - 006