pull/436/head
sunface 3 years ago
commit 1c4f8b0be6

@ -43,7 +43,7 @@ fn main() {
let mut values: [i32; 2] = [1, 2];
let p1: *mut i32 = values.as_mut_ptr();
let first_address = p1 as usize; // 将p1内存地址转换为一个整数
let second_address = first_address + 4; // 4 == std:mem::size_of::<i32>()i32类型占用4个字节因此将内存地址 + 4
let second_address = first_address + 4; // 4 == std::mem::size_of::<i32>()i32类型占用4个字节因此将内存地址 + 4
let p2 = second_address as *mut i32; // 访问该地址指向的下一个整数p2
unsafe {
*p2 += 1;

Loading…
Cancel
Save