Reputation: 344
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)
Upvotes: 0
Views: 63
Reputation: 19221
The *
is related to the type, not the function.
You should read it as struct Person *
returned by Person_create(char *name, int age, int height, int weight)
.
So the function returns a pointer to struct Person
.
it's a common:
[return type] func([arguments])
If you wanted to write a function pointer, you would have:
[return type] (*func_pointer_name)([arguments])
i.e.
struct Person * (*person_create_p)(char *, int, int, int) = &Person_create;
Upvotes: 4