Passing by reference to functions
Hi all,
I have a question about passing pointers to functions. Here's what I am doing.. I am defining a pointer to an array in my main and passing this pointer to a function.
Inside this function I am dynamically allocating a certain amount of memory to the pointer that was passed and filling in the array. But my program crashes if I try to access this array from the main. I tried out several stuff and found that I either have to return a pointer to the array that was filled (basically return the same pointer that I passed to the function) or I have to do the allocation of memory inside the main function itself in order for the program to work.
I am passing a pointer to the function in the first place because I dont want to return any values from the function. I can do the dynamic memory allocation in the main function itself. But i feel that my function will be more self sufficient and rounded if i do the memory allocation inside the function itself (reduce dependence on outside values). Do you have any suggestion how I can solve this issue.. Appreciate your help.
best,
Avinash