指针
引用其实可以转换为指针:
fn main() -> std::io::Result<()> {
let a = 8;
let b = &a as *const i32 as *mut i32;
unsafe {
*b = 99;
}
println!("a = {0}", a); // 99
Ok(())
}
2023-12-21 17:59:33
引用其实可以转换为指针:
fn main() -> std::io::Result<()> {
let a = 8;
let b = &a as *const i32 as *mut i32;
unsafe {
*b = 99;
}
println!("a = {0}", a); // 99
Ok(())
}