How to Use std

:ptr for Pointer Operations

Use std::ptr functions inside unsafe blocks to perform low-level memory reads, writes, and copies in Rust.

Use std::ptr functions like read, write, and copy inside an unsafe block to perform low-level pointer operations that bypass Rust's safety checks.

use std::ptr;

fn main() {
    let mut x = 5;
    let ptr = &mut x as *mut i32;

    unsafe {
        ptr::write(ptr, 10);
        let val = ptr::read(ptr);
        println!("{val}");
    }
}

This code writes 10 to the memory address of x and reads it back, demonstrating direct memory manipulation.