#include <iostream>
#include <vector>
#include <array>
using namespace std;
int main()
{
std::vector<int> vec100(100); // a vector of 100 ints
std::vector<int> vec2(2); // a vector of 2 ints
std::array<int,100> arr100; // an array of 100 ints
std::array<int,2> arr2; // an array of 2 ints
// notice how the number of elements does not change the size
// of the vector itself:
cout << "sizeof vec100 = " << sizeof(vec100) << endl;
cout << "sizeof vec2 = " << sizeof(vec2) << endl;
// This is because the vector does not contain the elements, but rather
// it contains a pointer to them. This means to access the elements,
// it has to dereference that pointer, which means an extra memory access
// On the other hand... notice how the number of elements does
// change the size of an array:
cout << "sizeof arr100 = " << sizeof(arr100) << endl;
cout << "sizeof arr2 = " << sizeof(arr2) << endl;
// This is because the array does actually contain its elements and not
// merely a pointer to them. This allows it to avoid that extra memory
// access and thus perform slightly better in high-demand situations.
//
// Note that this is only possible in array because it knows the size
// at COMPILE TIME and therefore it cannot resize it at runtime.
//
// Vector cannot do this because it needs to be able to adjust the size
// at runtime. Any dynamically sized container is going to have the
// same issue.
return 0;
}