#include #include int main(int argc, char *argv[]) { /* A final important C feature is "typedef" and "struct" */ /* this allows custom types that can gather related information into one */ /* variable. */ typedef struct {double *arr; int NX; int NY; } arr2d; arr2d A; if ( argc != 3 ) { printf("ERROR\n"); exit(-1); } A.NX = atoi(argv[1]); A.NY = atoi(argv[2]); if ( A.NX < 1 || A.NY < 1 ) { printf("ERROR\n"); exit(-1); } /* Now we use the standard library functions malloc() and sizeof(). malloc - requests a block of contiguous memory from the operating system sizeof - returns the size (in bytes) of a type, so that nx*ny*sizeof(*A) will return memory needed for nx*ny doubles (*A). */ printf("Allocating memory for double array of size %d x %d\n",A.NX,A.NY); A.arr = (double *)malloc(A.NX*A.NY*sizeof(*A.arr)); for (int j=0;j