#include #include int main(int argc, char *argv[]) { /* Very common to use pointers instead of multi-dimensional arrays in C */ /* in many large C projects this is quite a common approach for regular arrays */ double *A; int nx, ny; if ( argc != 3 ) { printf("ERROR: Needs 2 arguments\n"); exit(-1); } nx = atoi(argv[1]); ny = atoi(argv[2]); if ( nx < 1 || ny < 1 ) { printf("ERROR: Values must > 0 \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",nx,ny); printf("Sizes %d %d\n",sizeof(*A),sizeof(A)); A = (double *)malloc(nx*ny*sizeof(A)); printf("Loc A %p\n",A); if( A == NULL ) {printf("Cant allocate %d bytes\n",nx*ny*sizeof(A)); exit(-1);} for (int j=0;j