Google News
logo
Rust - Interview Questions
Explain the difference between an array and a vector.
An array is a collection of fixed sizes of elements belonging to the same type and allocated on the stack. The size of the array must be known at compile-time and cannot be changed at runtime.

A vector, on the other hand, is a dynamic-size collection of elements of the same type, allocated on the heap. Vectors are implemented using a Vec T type, where T is the type of elements in the vector. Vectors can grow or shrink in size as needed during runtime.
Advertisement