Last active
March 20, 2017 00:08
-
-
Save hadronized/1fc7534cd08e4fe55a926ab262593144 to your computer and use it in GitHub Desktop.
This file contains 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
// Without compiling nor running the following program, what do you expect its output to be? :) | |
// Have a great monday! | |
fn main() { | |
let mut a: u16 = 42; | |
let b: u16 = 7; | |
println!("before, a: {}\tb: {}", a, b); | |
unsafe { foo(&mut a as *mut u16 as *mut u32); } | |
println!("after, a: {}\tb: {}", a, b); | |
} | |
unsafe fn foo(a: *mut u32) { | |
*a = (42 << 16) + 7; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment