TheNemesis584 - 8 months ago 64

C Question

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?

Answer

so is it possible to save matrix as element of an array?

**YES**, you can use a **3-D array** to store it's elements as matrices

something like `array[no_of_matrices][row_no][column_no]`

for example:

```
int arr[2][2][2];
//this would store 2 arrays of dimensions 2*2
```

additionally if you want arrays of different dimensions the you can create `**array[no_of_matrices]`

and use **dynamic memory allocation** to allocate memory according to required dimensions of each matrix.

Source (Stackoverflow)