I have a segmentation fault in the code below, but after I changed it to pointer to pointer, it is fine. Could anybody give me any reason?
void memory(int *
You need a pointer to pointer because you need to return the value of the newly allocated pointer.
There is three ways to return that value (2 if you use C):
The third way has definitely my preference.
(and not, I won't admit you could also use a global, it's not a fourth way but an horror).