Pb with passing a row of a matrix to a function
brnstnd at stealth.acf.nyu.edu
brnstnd at stealth.acf.nyu.edu
Sun Apr 15 10:17:42 AEST 1990
In article <19604 at boulder.Colorado.EDU> olivier at 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
More information about the Comp.lang.c
mailing list