Consider the following code snippet:
#include using namespace std; void sub(vector& vec) { vec.push_back(5); } int main()
Because you gave sub the adress of the vector in the heap, it will allocate in the heap. If there's no space left, exception should be thrown.