What's better/more efficient - calloc
or malloc
?
I want to initialise structs, that refer to other instances of the same struct also
VARIANT 1
person *new_person() {
struct _person *person = calloc(1, sizeof(person));
person->name = NULL;
person->child = NULL;
return person;
}
VARIANT 2
person *new_person() {
struct _person *person = malloc(sizeof(person));
person->name = NULL;
person->child = NULL;
return person;
}
The struct
typedef struct _person {
*void name;
struct _person *child;
} person;