为什么在C结构定义中有嵌套指针?

Luc*_*ley 5 c syntax struct pointers function

我正在通过学​​习C The Hard Way来努力,并且正在努力理解练习16中的内容:结构和指针.

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;
}
Run Code Online (Sandbox Code Playgroud)

我理解struct Person将一个指针(*person_create)返回到struct的开头.但是为什么有人第二个结构定义立即嵌套在里面?指着谁?

有人可以为我阐明这一点.或者指出我在C中更好地解释结构定义.

Sou*_*osh 5

我明白struct Person返回一个指针(*person_create)

等等,这不是你的想法,或者至少你不这么说......

person_create()是一个函数,它返回一个指针struct Person.这不是定义struct Person.

现在,那说,来到你的实际排队,struct Person *who 没有定义struct Person,而是,它定义了一个变量who,它是一个指针struct Person.

为了便于理解,请考虑int someRandomVariable = 0.它没有定义int,对吧?它定义了一个someRandomVariable类型的变量int.