Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!uflorida!haven!adm!cmcl2!stealth.acf.nyu.edu!brnstnd From: brnstnd@stealth.acf.nyu.edu Newsgroups: comp.lang.c Subject: Re: Pb with passing a row of a matrix to a function Message-ID: <3914:Apr1500:17:4290@stealth.acf.nyu.edu> Date: 15 Apr 90 00:17:42 GMT References: <19604@boulder.Colorado.EDU> Reply-To: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Distribution: usa Organization: IR Lines: 17 In article <19604@boulder.Colorado.EDU> olivier@alpo.colorado.edu () writes: [ function f(row) int *row ... takes as an argument a ``pointer to a ] [ row of a matrix''; f(&matrix[i]) is wrong type with int **matrix ] You've correctly analyzed the problem. To see the solution, think about the use of row. row is a pointer to integers; *row, *(row + 1), and so on are the elements of that row. You want that row to be a row of your matrix, i.e., the elements matrix[i][j] == *(*(matrix + i) + j) for j 0, 1, and so on. You want *(row + j) to be *(*(matrix + i) + j); so row should equal *(matrix + i), i.e., matrix[i]. In other words: f(matrix[i]), just as in any other competent language. By the way, you should describe row as ``a pointer to the elements of a row of a matrix,'' not ``a pointer to a row of a matrix.'' ---Dan