pull/434/head
Ziqiu Zhao 3 years ago committed by GitHub
parent 118474c8dd
commit a8af55b0a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -43,7 +43,7 @@ fn main() {
let mut values: [i32; 2] = [1, 2]; let mut values: [i32; 2] = [1, 2];
let p1: *mut i32 = values.as_mut_ptr(); let p1: *mut i32 = values.as_mut_ptr();
let first_address = p1 as usize; // 将p1内存地址转换为一个整数 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 let p2 = second_address as *mut i32; // 访问该地址指向的下一个整数p2
unsafe { unsafe {
*p2 += 1; *p2 += 1;

Loading…
Cancel
Save