Ok but what is *string was a pointer to a struct or something that is not a
"literal", can I still omit malloc?
When your function receives a pointer from a calling routine, you do
not necessarily need to call malloc.
If the calling routine tries to pass you an uninitialized
pointer, that routine invokes undefined behavior and anything can
happen before, during, or after your function executes.
Now that you know the pointer has been initialized to some
value, it may be appropriate to check if that value is NULL. You do
this if your function would normally try to dereference the pointer
since dereferencing a NULL pointer would invoke undefined behavior.
If you want to change the value of the pointer (the address it points
to), you could call malloc. You could also assign it the address of
an object of the correct type that happens to be in scope to your
function. Whether you do this or not depends on the nature of your
function. Since C passes arguments to functions by value, any change
you make to the pointer's value is local to your function unless you
somehow "export" the new value to the calling routine, as with a
return statement.
In my experience, most functions that receive pointers as arguments do
not call malloc but use the value of the pointer as passed by the
calling routine. I think you should go back and reread the text that
raised your initial question. All automatic variables local to your
function, including parameters, disappear when your function returns.
However, this has no affect on the variables in the calling routine
that may have been used as arguments.
Remove del for email