Created
November 3, 2021 00:26
-
-
Save Shaun289/aa5caf1c7690dee4863268f03a78ae24 to your computer and use it in GitHub Desktop.
Rust study : literals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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