Vectors are used a lot in C++ as the go-to dynamic size container, but how do they actually work and what do they look like on the stack and heap?, Vector allocates memory on the heap and it is mutable, Array allocates memory on stack or on the heap (depending on how do you use it) and is immutable. Are you talking about regular (c-style) arrays or the std::array class? Frankly, if you use the former in a C++ program, you're probably wrong., newArray = new int[size1 * size2]; size1 and size2 are variables. Standard C++ does not support variable length arrays (VLA). With standard C++ the size of the array must be known at compile time. So your original lines 1-4 are correct., //How to use vector to put elements inside the array. std::vector<myarray> heap_array (3); // Size is optional. Are there any code examples left? Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond., My goal is to create an array of vectors (with a capacity of 10 integers for each vector) on the heap. I can create my array easily enough: However, this creates an array of empty vectors., In C++, we can create a class with an vector and a size variable to represent the heap. We can implement the required functions as the member functions of this class.