Firstmate commented on a Page, dynamic multidimensional arrays Example  -  May 02, 2012

I'm not sure if this was done more out of demonstrating the code, but why not take:

    double ***ptr3;
    ptr3 = new double**[2];
    for( int i = 0 ; i < 2 ; i++)
    {
        ptr3[i] = new  double*[3];
    }
    for( int i = 0 ; i < 2 ; i++)
    {
        for( int j = 0 ; j < 3 ; j++)
        {
            ptr3[i][j] = new  double[4];
        }
    }

    for( int i = 0 ; i < 2 ; i++)
    {
        for( int j = 0 ; j < 3 ; j++)
        {
            for( int k = 0 ; k < 4 ; k++)
            {
                ptr3[i][j][k] = ( i * 3 + j ) * 4.1 + k * 0.1;
            }
        }
    }

And make it:

    double ***ptr3;
    ptr3 = new double**[2];
    for( int i = 0 ; i < 2 ; i++)
    {
        ptr3[i] = new  double*[3];
        for( int j = 0 ; j < 3 ; j++)
        {
            ptr3[i][j] = new  double[4];
            for( int k = 0 ; k < 4 ; k++)
            {
                ptr3[i][j][k] = ( i * 3 + j ) * 4.1 + k * 0.1;
            }
        }
    }
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.