Hi, I am not sure why the output of the double array r[][] is different the two times I call it. In the example below, i have set r[i][j] = i+j. Then I output it in two different loops and find that it does not output the same numbers.
int main()
{
int i,j,k;
double **r;
i=0;
r = new double*[5];
for(i=0;i<5;i++)
{
r[i] = new double[i+1];
for(j=i;j<5;j++)
{
r[i][j] = i+j;
cout << (r[i][j]) << endl; //This works
}
cout << endl;
}
You are accessing outside of your array bounds and are corrupting the heap as a result.
1 2 3 4 5 6 7
r = newdouble*[5];
for(i=0;i<5;i++)
{
r[i] = newdouble[i+1]; // r[0] is only 1 element large
for(j=i;j<5;j++)
{
r[i][j] = i+j; // yet you are accessing r[0][4] -- OUT OF BOUNDS