How to create a matrix structure in C?
How to create a matrix structure in C? I'm a beginner in C, but I'm currently trying to create a matrix data structure that could be used in different functions without having to explicitly pass the number of columns and number of rows (example: matrixMult(matrix A, matrix B) instead of matrixMult(A, B, rowsA, columnsA, rowsB, columnsB) ). My approach so far has been to declare a struct such as matrixMult(matrix A, matrix B) matrixMult(A, B, rowsA, columnsA, rowsB, columnsB) typedef struct matrix{ int rows; int columns; int **data; }matrix; And then, to properly allocate the matrix, I'm trying to use the following function matrix startmatrix(matrix mat,int n_row, int n_col){ int i=0; mat.rows=n_row; mat.columns=n_col; mat.data=(int **) calloc(n_row,sizeof(int *)); for(i=0;i<n_row;i++){ mat.data[i]=(int *) calloc(n_col,sizeof(int)); } return mat; } Which (to my understanding) allocates the rows containing the columns, and ...