So my understanding is that if I have a function with a pointer as parameter and I change the value of it in the function and want that change also to occure outside the function I don't have to return the pointer. For example:
void fubar(char * a)
{
*a = 5;
}
In this case after calling the function the pointer I used should have the value 5 because the address is still the same right?
But lets say you change the memory dynamically in a function:
void newMem(char * b)
{
b = (char*) realloc((void*) b, 10 * sizeof(char))
//etc...
}
Couldn't it be, that because the memory at the previous location is not sufficient, the pointer will point to some other address after realloc() making this function dangerous. It works just fine in the programm I wrote but I fear it could have a bad outcome as soon the just mentioned case will occure.
So would it be better to do it with a return value like this:
char * newMem(char * b)
{
b = (char*) realloc((void*) b, 10 * sizeof(char))
//etc ....
return b;
}