Yes, you can remove temp and work with x[0] directly:
Code:
#include <stdio.h>
#include <stdlib.h>
#define TEST
#define N 10
#define M 5
int main()
{
int** p = (int**)malloc(N * sizeof(int*));
int k = 0;
if (p)
{
// Allocate one master block
p[0] = (int*)malloc((N * M) * sizeof(int));
// Split up the master block
for (int x = 1; x < N; ++x)
{
p[x] = p[0] + (x * M);
}
// Initialize the array
for (int x = 0; x < N; ++x)
{
for (int y = 0; y < M; ++y)
{
p[x][y] = k++;
}
}
#if defined(TEST)
// Print for testing
for (int x = 0; x < N; ++x)
{
for (int y = 0; y < M; ++y)
{
printf("%3d", p[x][y]);
}
putchar('\n');
}
#endif
// Clean up the mess
free(p[0]);
free(p);
}
}