C allocate 2d array and free them.
                    int height = 3;
                    int width = 4;
                    // allocate memory for height x width 2d array.
                    int** pt2 = (int**)malloc(sizeof(int*)*height);
                    for(int i=0; i< height; i++){
                        pt2[i] = (int*)malloc(sizeof(int)*width);
                    }

                    *pt2[0] = 1;
                    *pt2[1] = 2;
                    ...
                    
                    // deallocate the memory
                    for(int i=0; i< height; i++){
                        if(pt2[i] == NULL)
                            free(pt2[i]);
                    }
                    if(pt2 != NULL)
                        free(pt2);
                    
Cpp new and delete in 2D
                    // two dimension array
                    int** arr = (int**) new int*[ncol];    
                    // allocate row
                    for(int j=0; j < 2; j++){
                        arr[j] = (int*) new int[nrow];
                    }
                    //
                    for(int i=0; i < ncol; i++) 
                        delete[] arr[i];
                    delete[] arr;
                    
Allocate and Deallocate functions in C++
                    int* allocate(int size){
                            return new int[size];
                    }

                    void deallocate(int*& pt){
                            delete[] pt;
                                pt = NULL;
                    }
                    
Why You can NOT find the length of array if you allocate memory dynamically
                    int* arr = new int[10];
                    int len = sizeof(arr)/sizeof(int); // not equal 10

                    int arr[10];
                    int len = sizeof(arr)/sizeof(int); // => equal 10

                    
Dynamically allocate two dimension array in C
                    int height = 3;
                    int width  = 4;
                    int* pt = (int*)malloc(sizeof(int)*width);

                    int** array = (int**)malloc(sizeof(int*)*height);
                    for(int i = 0; i < height; i++)
                        array[i] = (int*)malloc(sizeof(int)*width);
                    


Allocate and Deallocate 3D array or tripple pointers in C/C++/ObjectiveC with malloc