C++ create 2D array

How to create dynamic 2d array in C++ ?
This is a code to create 2D array in C++ :

float **ArrayLib::create2Array_float(int row, int col)
    int i;
    float **out;

    out = new float*[row];
    out[0] = new float[row*col];
    for(i=1; i<row; i++)
        out[i] = out[i-1] + col;
    return out;

If you want to remove or free array 2D, you can use this code :

bool ArrayLib::delete2Array_float(float **array)
    delete [] array[0];
    delete [] array;

    return true;

Add a Comment

Your email address will not be published. Required fields are marked *