GitHub

Practice

Practice - 008

A program to print the type of a variable

fn print_type_of<T>(_: &T) {
println!("{}", std::any::type_name::<T>())
}
fn main() {
practice8()
}
fn practice8() {
let a = 2;
let b = 5.0;
print_type_of(&a);
print_type_of(&b);
}

Result

i32
f64
Previous
Practice - 007