Rust references vs raw pointers
WHAT IT TESTS: safety invariants of references. OUTLINE: references are borrow-checked, always valid, aliasing-controlled, non-null; raw pointers carry no guarantees, can be null, dangling, or aliased, and dereferencing needs unsafe.
WHAT IT TESTS: understanding what the borrow checker enforces and what unsafe surrenders. ANSWER OUTLINE: &T and &mut T are guaranteed non-null, properly aligned, pointing to a live value, and obey aliasing rules: many shared or one exclusive. The compiler tracks lifetimes so they never dangle. Raw pointers *const T and *mut T have none of these guarantees: they may be null, dangling, misaligned, or aliased, are not lifetime-tracked, and dereferencing requires unsafe. RED FLAG: assuming raw pointers still get borrow-check protection.
Read the original → interview
- #rust
- #unsafe
- #pointers
- #references
- #memory-safety
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.