However, you must understand that any dynamically allocated 2D array is not guaranteed to be contiguous at all. This is because subsequent malloc calls are not guaranteed to allocate memory next to the previous malloc call. So therefore, only a 1D array is guaranteed to be be contiguous.
The compiler cannot, and I repeat, it cannot, optimize this and place it in a contiguous space because it has no control over malloc.
Malloc is a function that calls OS API, which the compiler has no control over.
Although, if you want, it's quite possible to create a contiguous 3/+D array:
Code:
int (*p)[10][10] = malloc(10 * 10 * 10); /* malloc(x * y * z); */
p[9][9][9] = 0;
free(p);