Passing a matrix in a function (C)

You need to pass a pointer with as much levels of indirection (*) as the number of dimensions of your matrix.

For example, if your matrix is 2D (e.g. 10 by 100), then:

void ins (int **matrix, int row, int column);

If you have a fixed dimension (e.g. 100), you can also do:

void ins (int (*matrix)[100], int row, int column);

or in your case:

void ins (int (*matrix)[SIZE], int row, int column);

If both your dimensions are fixed:

void ins (int matrix[10][100], int row, int column);

or in your case:

void ins (int matrix[SIZE][SIZE], int row, int column);

Leave a Comment