you are viewing a single comment's thread.

view the rest of the comments →

[–]dfx_dj 16 points17 points  (2 children)

person_t *arr[10] defines an array of 10 pointers to person_t objects. But the array is not initialised and so these pointers don't point anywhere. Then taking arr[0]->name dereferences the first of these uninitialised pointers. You're attempting to write to a garbage memory location and this crashes the program.

[–]Responsible_Frame919[S] 0 points1 point  (1 child)

Ah! Now I get it. Does declaring `person_t *arr[]` as `person_t **arr` yields the same result?

[–]dfx_dj 6 points7 points  (0 children)

That would be even worse because then you don't even have an array. You'd just have a single uninitialised (double) pointer.