I was reading about structures in c, and came across this code. I was hoping somebody could help me break this code down and understand what its' doing.
struct Person *Person_create(char *name, int age, int height, int weight)
{
struct Person *who = malloc(sizeof(struct Person));
assert(who != NULL);
who->name = strdup(name);
who->age = age;
who->height = height;
who->weight = weight;
return who;
};
Specifically, this is the portion of the code that I don't understand
*Person_create(char *name, int age, int height, int weight)
*
is related to the type, not the function. You should read it asstruct Person *
andPerson_create(char *name, int age, int height, int weight)
. So the function returns a pointer tostruct Person
.