So I was given a struct:
struct Xxx
{
struct Yyy{...};
Yyy **yyys; // matrix of yyys
};
I am confused about how pointer to pointer is related to a matrix?
And how can I initialize a new Yyy and a new Xxx?
The first level pointer would point to an array of pointers, and each second level pointer would point to an array of Yyy.
They can be set up as follows:
struct Yyy **makeMatrix(int rows, int cols)
{
int i;
struct Yyy **result = malloc(rows*sizeof(struct Yyy *));
for (i = 0; i < rows; i++) {
result[i] = malloc(cols*sizeof(struct Yyy));
}
return result;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With