#include #include #define NRows 3 #define NCols 4 int main(int argc, char *argv[]) { int i, j; double* p; // We uses this reference variable to access // dynamically created array elements p = calloc(NRows*NCols, sizeof(double) ); // 3x4 = 12 elements for ( i = 0; i < NRows; i++ ) for ( j = 0; j < NCols; j++ ) p[i*NCols + j] = i+j; // put value i+j in array element p[i][j] for ( i = 0; i < NRows; i++ ) { for ( j = 0; j < NCols; j++ ) printf("p[%d][%d] = %lf ", i, j, p[i*NCols + j] ); putchar('\n'); } free(p); // Un-reserve the first array }