I know that in order to malloc an array of pointers to arrays, the syntax should be:
(int**)malloc(numberOfDesiredElements*sizeof(int*))
Accidentally, I forgot to put the numberOfDesiredElements* in front of size. It was messing up my program throwing random segmentation faults, i.e. sometimes the program outputted correctly, sometimes it seg faulted.
Can someone explain what happened when I did not indicate how many slots I wanted?
Thanks!
It’s just an ordinary multiplication, not magic syntax; so it allocated space for 1 instead of 3.