how to free a 2d array correctly

C
for (int i = 0; i < N; i++)
{
    int* currentIntPtr = ptr[i];
    free(currentIntPtr);
}
Source

Also in C: