Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!zaphod.mps.ohio-state.edu!samsung!crackers!m2c!umvlsi!umaecs!lim From: lim@ecs.umass.edu Newsgroups: comp.lang.c Subject: 2D arrays and pointers in ANSI C (summary) Message-ID: <11661.275accb9@ecs.umass.edu> Date: 3 Dec 90 22:07:53 GMT Lines: 37 Thanks to all who answered my question about 2D arrays and pointers in ANSI C. Here's a summary of what I'm using: int main(void) { double **matrix /* matrix is a 1D array of pointers; each pointer repre- */ int m = ?, n = ?; /* sents the address of a 1D array of doubles. */ int i; /* For a m x n matrix */ matrix = (double **) malloc(m * sizeof(double *)); /* I use calloc to initialize the elements to zero */ for ( i = 0; i < m; i++ ) matrix[i] = (double *) calloc(n,sizeof(double)); test_matrix(matrix,m,n); } void test_matrix(double **matrix, int m, int n) { int i, j; for ( i = 0; i < m; i++ ) { for ( j = 0; j < n; j++ ) matrix[i][j] = 4.0; } . . . } Jonathan Lim Brought to you by Super Global Mega Corp .com