Difference: Vectors variable length whilst Arrays are fixed.
std::array<T, num>
num is the number of elementsa[1] is not bound checkeda.at(1) is bound checked
std::out_of_rangeFor backwards compatibility, c style arrays exist, but are not upgraded.
int a[10] = {};
float b[3] = {0.1, 0.2, 0.3}
std::vector<T>
for(optional_init; auto i : container_with_iterator)
e.g.
for(std::vector<int> a{1,2,3,4,5,6,7}; auto i : a){
std::cout << i << ", ";
}
The optional init is only executed once, and a will only be valid for the for loops scope.
for(std::vector<int> a{1,2,3,4,5,6,7}; auto i : a){
std::cout << i << ", ";
}
a[1] = 5; // ERROR