Vec<T> is a growable array on the heap. Use push, indexing, and iteration—mind bounds and ownership when moving elements out.
Common operations
let mut v = vec![1, 2, 3];
v.push(4);
let third = v[2];
Important interview questions and answers
- Q: Vec vs array?
A: Arrays fixed size on stack; Vec grows on heap with capacity management.
Self-check
- What macro creates a vector literal?
- What happens on out-of-bounds index?