Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do all STL containers return their elements by reference?

Tags:

People also ask

Are STL containers passed by reference?

@BjörnPollex Yes! I forgot to mention that.


I am learning STL these days and I was wondering if STL containers return by reference?

e.g:

vector.first();
map[key];
*vector.begin();
Or any possible return that ends with element (or value type) of container

e.g:

std::vector<int> elements;
elements.push_back(20);
elements[0]=60; // this will also change the value
elements.front() = 23; // even the functions also behave same way like subscript operator

is this the case with all containers? or there are some points to consider which I didn't show?