Skip to content

Instantly share code, notes, and snippets.

@Shaun289
Created November 3, 2021 00:26
Show Gist options
  • Save Shaun289/aa5caf1c7690dee4863268f03a78ae24 to your computer and use it in GitHub Desktop.
Save Shaun289/aa5caf1c7690dee4863268f03a78ae24 to your computer and use it in GitHub Desktop.
Rust study : literals
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/cast/literals.html
compiled on https://play.rust-lang.org/
result :
size of x in bytes: 1
size of x in bytes: 4
size of x in bytes: 4
size of x in bytes: 4
size of x in bytes: 8
*/
use std::mem;
fn main()
{
let x = 1u8;
let y = 2u32;
let z = 3f32;
let i = 1;
let f = 1.0;
println!("size of x in bytes: {}", mem::size_of_val(&x));
println!("size of x in bytes: {}", mem::size_of_val(&y));
println!("size of x in bytes: {}", mem::size_of_val(&z));
println!("size of x in bytes: {}", mem::size_of_val(&i));
println!("size of x in bytes: {}", mem::size_of_val(&f));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment