I have a function which gets as a parameter a pointer to array,
e.g. int** segs.
I need to allocate (in the function-body) memory for the array, which has size 100 for example.
My attempt was:
*segs=(int*)(malloc(100));
So far so good.
I put a value into *segs[0], and still everything is great.
But... when I try to reach *segs[1], I get an "invalid write of size 4" error from valgrind, which leads to seg-fault.
I have no idea why does that happen.
I tried to reach to *segs[2], but then I get even something weirder-
Error of uninitialised value of size 8.
*segs[0]- be care of operator precedence. Either disambiguate, e.g(*segs)[0] = ...or use a local var and save to your target ptr-to-ptr after everything else is done.*segs?