我正在閱讀有關c結構,並遇到此代碼。我希望有人能夠幫助我分解這些代碼並理解它在做什麼。功能指針和結構
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;
};
具體而言,這是我不理解
*Person_create(char *name, int age, int height, int weight)
的'*'是關係到類型,而不是功能。你應該把它看作'struct Person *'和'Person_create(char * name,int age,int height,int weight)'。所以函數返回一個指向'struct Person'的指針。 – Myst