← All Exercises

Smart Pointers Box and Rc

intermediaterust~20min

Background

Smart pointers provide controlled memory management beyond Rust default stack allocation.

Problem

Demonstrate Box for single ownership heap data and Rc for shared ownership with reference counting.

Input

Data to allocate

Output

Heap-allocated or shared data

Sample tests

Sample 1

Input: Box::new(42)
Expected: heap allocated

Your solution

Learning objective

Learn heap allocation and shared ownership patterns