#include #include int main () { double A[10][10]; // Static allocation of space to array A. double **B; // We'll use malloc to assign space to B. int i; printf ("BEFORE malloc: Address A=%p Address B=%p\n", A, B); // Prints an address for A, but zero for B // Assign space for first dimention of B (an array of pointers-to-double) B = (double**) malloc (10 * sizeof(double*)); for (i=0; i<10; i++) { B[i] = (double*) malloc (sizeof(double)); } printf ("AFTER malloc: Address A=%p Address B=%p\n", A, B); // Prints an address for A and newly allocated address for B. // Two ways of assigning values: A[3][4] = 5.55; *((double*)A + 5*10 + 6) = 6.66; printf ("A[3][4]=%lf A[5][6]=%lf\n", A[3][4], A[5][6]); // Prints 5.55 and 6.66. // Twy ways of assigning values: B[3][4] = 7.77; *((*(B + 5)) + 6) = 8.88; printf ("B[3][4]=%lf B[5][6]=%lf\n", B[3][4], B[5][6]); // Prints 7.77 and 8.88 // Free the individual small arrays: for (i=0; i<10; i++) { free (B[i]); } // Free the array of double-pointers: free (B); }