GitHub

Practice

Practice - 010

A program to print the size of a variable

use std::mem;
fn main() {
practice10()
}
fn practice10() {
let a = 5;
println!("a is {} bytes", mem::size_of_val(&a));
let b: [u8; 13] = [0; 13];
println!("b is {} bytes", mem::size_of_val(&b));
}

Result

a is 4 bytes
b is 13 bytes
Previous
Practice - 009