Reputation: 59
I was wondering is it possible in C language to save couple of matrices in an array and how to do that? Like, I pass a static matrix to a function and in a several steps I use the same matrix for different calculations, so I need to save every matrix with different result somewhere, so is it possible to save matrix as element of an array?
Upvotes: 0
Views: 750
Reputation: 5457
so is it possible to save matrix as element of an array?
Yes, you can use a three dimensional array to store it's elements as matrices. Something like array[no_of_matrices][row_no][column_no]
would do fine
example:
int arr[2][2][2];
// this would store 2 matrices of dimensions 2*2
Additionally, if you want arrays of different dimensions then you can create **array[no_of_matrices]
and use dynamic memory allocation to allocate memory according to required dimensions of each matrix.
Upvotes: 2