Here is a ``better'' way to construct a dynamic n-by-m array. Assume n and m are of type size_t. Handling of arithmetic wrap-around (if necessary) and malloc failure are omitted for brevity.
type **x = malloc(n * sizeof *x);
x[0] = malloc(n * m * sizeof *x[0]);
for (size_t i = 1; i < n; i++)
x[i] = x[i-1] + m;