juniorRust

What is a Vec in Rust?

Updated May 24, 2026

Short answer

Vec is a growable array stored on the heap.

Deep explanation

Vectors dynamically resize and store elements contiguously in memory, providing efficient indexing and iteration.

Real-world example

Storing lists of user IDs or logs.

Common mistakes

  • Assuming fixed size like arrays.

Follow-up questions

  • How does Vec grow?
  • Is Vec contiguous?

More Rust interview questions

View all →