Lesson 46 of 50 · rust
Smart Pointers (Box, Rc, Arc)
Duration: 12 minutes
Lesson 46 of 50 · rust
Duration: 12 minutes
Box<T> allocates data on the heap.\n- Rc<T> provides single‑threaded reference counting.\n- Arc<T> provides atomic reference counting for multi‑threaded scenarios.\n\nrust\nuse std::rc::Rc;\nuse std::sync::Arc;\n\nfn main() {\n let b = Box::new(5);\n let rc = Rc::new(10);\n let arc = Arc::new(15);\n println!(\"Box: {}, Rc: {}, Arc: {}\", b, rc, arc);\n}\n\n