Why using a pointer of a self-defined structure in the CS50 Inheritance problem

21 Views Asked by At

Hi here is the link of the homework description. And here is the part of the code that's relevant:

typedef struct person
{
struct person *parents[2];
char alleles[2];
} person;

const int GENERATIONS = 3;

person *create_family(int generations);
void print_family(person *p, int generation);
void free_family(person *p);
char random_allele();

Please help me understand why we want the return value ofcreate_family(int generations) to be a pointer, not just a variable person. What's the advantage of using pointer here?

I speculate that's because it's more efficient, as we can free the memory as we go, but I'm not sure.

0

There are 0 best solutions below