I\'m trying to do something with an array (malloc-ed), namely arr of a custom struct. The array is passed by reference to a function. I get a segfault whenever I tr
Your problem is the line
(*arr[1])->i = 3;
Because the subscripting operator's evaluation precedes the dereferencing's evaluation it is equivalent to the following:
(*(arr[1]))->i = 3;
This is obviously wrong. You need
(*arr)[1]->i = 3;
therefore.
Notes:
#include to resolve the warningfoo*** pointing to foo**) is unnecessary; just copy by value(in addition to the upper note) a good old 1D array should actually be sufficient in your case
call free after malloc