Explain the difference between an immutable reference (`&T`), a mutable reference (`&mut T`), and a `Box<T>` in Rust.

Go & Rust interview question for Advanced practice.

Answer

&T: Borrows data immutably. &mut T: Borrows data mutably. Box<T: Owns data allocated on the heap.

Explanation

The correct answer is A. It accurately describes the core functionality: &T is a shared, immutable borrow; &mut T is an exclusive, mutable borrow; and Box<T is an owned pointer to heap-allocated data. The other options incorrectly mix up the concepts of borrowing vs. ownership, mutability, and memory location.

Related Questions