// Define Person
typedef struct Person {
char *name;
int age;
} person_t;
// Init person in heap
person_t *create_person_v1(char *name, int age)
{
person_t *person = calloc(1, sizeof(person_t));
person->name = name;
person->age = age;
return person;
}
// Init person on stak? a static struct I guess?
person_t create_person_v2(char *name, int age)
{
return (person_t) {name, age};
}
The code above has a definition of Person and two helper functions for its further initialization.
I don't really understand the difference between them, and what are the benefits of having each?
Is it something more than just accessors -> and . ?