Let's say you have something like this
#include <iostream>
#include <vector>
using namespace std;
vector<int> test()
{
vector <int> x(1000);
for (int i = 0; i < 1000; i++)
{
x[i] = 12345;
}
return x;
}
int main(int argc, const char * argv[])
{
vector<int> a = test();
return 0;
}
where inside the function you create a vector and fill it with some elements (in this case I selected 12345, but they will not necessarily be the same).
I read that vector elements are stored on the heap, while link and header data is stored on the stack. In the above code, when it returns x, the instance instance must be called, and this takes O (n) time to copy all the elements to the new vector.
, , - , , , - , ?