Declare raw pointers as *const T or *mut T and dereference them inside an unsafe block to access memory directly.
Use raw pointers by declaring them as *const T or *mut T inside an unsafe block, then dereference them with *ptr to access the data.
fn main() {
let mut num = 5;
let r1 = &num as *const i32;
let r2 = &mut num as *mut i32;
unsafe {
println!("r1: {}, r2: {}", *r1, *r2);
}
}
Raw pointers are direct memory addresses that Rust does not automatically check for safety. You use them only when you need to bypass Rust's safety rules, such as when talking to C code or writing low-level drivers. Think of them as a physical address on a map where you must manually ensure the house exists before walking in.