Rotate an image (2D array) by 90 degrees recursively with low memory usage I'm looking for comments on coding style, passing arguments, ...etc.

#include &lt;iostream&gt;

using namespace std;

void printImage(int** img, int N){

    //check if image pointer is NULL
    if(img == NULL){
        return;
    }

    //check if any of the columns of the image are null (since its essentially an array of pointers)
    for(int i=0; i&lt;N ; i++){
        if(img[i] == NULL){
            return;
        }
    }

    for(int i=0; i&lt;N ; i++){
        for(int j=0; j&lt;N ; j++){
            cout&lt;&lt;img[i][j]&lt;&lt;",";
        }
        cout&lt;&lt;endl;
    }
}

// ROTATE IMAGE BY 90 DEGREES RECURSIVELY
void do_rotateImageInplace(int** img, int N, int row, int col){

    //base condition --&gt; return: do this by check if we need to go deeper into the "peels of the onion :)"
    if(row &gt; N-row-1 || col &lt; 0 || N==1)
    {
        return;
    }

    // Tmp usage --&gt; to store row or column being rotated
    int* tmp = new int[N-row];

    //backup row
    for(int i=row; i&lt;N-row ; i++){
        tmp[i]=img[i][col];
    }

    //copy row into col
    for(int i=N-row-1; i&gt;=row ; i--){
        img[i][col] = img[row][i];
    }

    //swap tmp with end row
    for(int i=N-row-1 ; i&gt;=row ; i-- ){
        int tmpVal = img[col][i];
        img[col][i] = tmp[N-i-1];
        tmp[N-i-1] = tmpVal;
    }


    // Swap end row into first col
    for(int i=N-(row)-2 ; i&gt;=row ; i--){
        int tmpVal = img[i][row];
        img[i][row] = tmp[N-i-1];
        tmp[N-i-1]=tmpVal;
    }

    // Swap first column backup into first row
    for(int i=row+1; i&lt;N-(row)-1 ; i++){
        img[row][i] = tmp[i];
    }

    delete[] tmp;

    do_rotateImageInplace(img, N, row+1, col-1);
}

void rotateImageInplace(int** img, int N){

    // Check if image pointer is NULL
    if(img == NULL){
        return;
    }

    // Check if any of the columns of the image are null (since its essentially an array of pointers)
    for(int i=0; i&lt;N ; i++){
        if(img[i] == NULL){
            return;
        }
    }

    // If image is less than 2 in size
    if(N&lt;2){
        return;
    }

    do_rotateImageInplace(img, N, 0, N-1);
}



int main(){

    //TEST CASES:
    int N = 5;
    int** img = new int*[N];
    int val = 0;
    for(int i=0; i&lt;N ; i++){
        img[i] = new int[N] {val++,val++,val++,val++,val++};
    }

    cout&lt;&lt;"******* original image ******"&lt;&lt;endl;
    printImage(img, N);

    rotateImageInplace(img, N);

    cout&lt;&lt;"******* rotated image ******"&lt;&lt;endl;
    printImage(img, N);

    for(int i=0; i&lt;N ; i++){
        delete img[i];
    }
    delete[] img;

}
First of all, I don't see why do_rotateImageInplace shall be recursive. And indeed, it is a tail recursive, and as such is trivially converted into a loop.

Second, the comments are seriously misleading. This is what they say:

//backup row
//copy row into col
    (hmm... now `col` is permanently destroyed)
//swap tmp with end row
    (hmm... the comment above says that tmp istelf is a row. Why would I want to swap rows?)


etc.

The only useful comment is about peeling the onion. And a good comment really wants to be a function name. So

for (int layer = 0; layer &lt; N/2; layer++)
    rotate_layer_inplace(img, N, layer);


seems like what you are trying to do.