How to Dereference Raw Pointers Safely

Dereference raw pointers in Rust by wrapping the access in an unsafe block to manually verify memory safety.

You must dereference raw pointers inside an unsafe block to opt out of Rust's compile-time memory safety checks. Raw pointers (*const T or *mut T) do not guarantee valid memory, so the compiler requires explicit permission to access the data they point to.

fn main() {
    let x = 5;
    let raw_ptr: *const i32 = &x;

    unsafe {
        println!("Value: {}", *raw_ptr);
    }
}