Q:

error while trying to build a matrix using vectors

I am trying to learn about the C++ standard library and started with vectors. I tried to implement a matrix using vectors. Below is my code.
#include <iostream>
#include <vector>

using namespace std;

int main()
{

vector< vector<double> > matrix;

double array1[5]={1,2,3,4,5};
vector<double> vec1(array1 , array1+5) ;
double array2[5]={11,32,23,24,25};
vector<double> vec2(array2 , array1+5) ;

matrix.push_back(vec1);
matrix.push_back(vec2);

for(int i=0;i<matrix.size();i++)
{
    for(int j=0;j<matrix[i].size();j++)
    {
            cout<<i<<j<<matrix[i][j]<<endl;
            //cout<<matrix[i][j]<<endl;

    }

}

return 0;

}

When I try to run the above code, I get the following error. 
terminate called after throwing an instance of 'std::bad_alloc'
what():  std::bad_alloc
Aborted (core dumped)

Could anyone please explain where I am going wrong.

A:

The line vector<double> vec2(array2 , array1+5) ; is wrong. It should be vector<double> vec2(array2 , array2+5) ;. The original is taking 2 arbitrary addresses and trying to make a vector. Since the address range [array2, array1+5) is not valid, undefined behavior occurs.

