请耐心等待我,我来自其他语言和新手到 c 并从http://c.learncodethehardway.org/book/learn-c-the-hard-way.html学习它
struct Person {
char *name;
int age;
int height;
int weight;
};
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 函数返回一个 struct Person 的指针。我不明白是(可能是因为我来自其他语言,erlang,ruby),为什么将它定义为
struct Person *Person_create(char *name, int age, int height, int weight)
不是
struct Person Person_create(char *name, int age, int height, int weight)
还有其他方法可以定义一个函数来返回一个结构吗?
对不起,如果这个问题太基本了。