B = (double **)malloc(m*sizeof(double *)); if ( B == NULL ) return NULL; B[0] = (double *)malloc(m*n*sizeof(double)); if ( B[0] == NULL ) { free(B); return NULL; } /* now set the other pointers */ for ( i = 1; i < m; i++ ) B[i] = B[0] + i*n;