@Pastifier initials is an output parameter provided by the caller of the function so that you do not have to allocate your own memory for the result. As specified in the initial code, you have to write your answer (the initials) to this buffer, and return this same buffer.
@dbtx This is a common pattern which enables function calls chaining. It is common in the standard library (strcpy(), memcpy(), memset(), ...)
It's a pointer to enough space for you to write the output, and then you return that same pointer. I'm not sure why people do it this way since the calling function already knows where to find the result. IMO the function's type would just be void in this case, unless you need to return int for a success/error code, but there may be another reason for it.
I don't understand why there's a field for initials in the parameters of the function, in C, when those are what you're trying to get. Could someone explain?
@Pastifier
initials
is an output parameter provided by the caller of the function so that you do not have to allocate your own memory for the result. As specified in the initial code, you have to write your answer (the initials) to this buffer, and return this same buffer.@dbtx This is a common pattern which enables function calls chaining. It is common in the standard library (
strcpy()
,memcpy()
,memset()
, ...)It's a pointer to enough space for you to write the output, and then you return that same pointer. I'm not sure why people do it this way since the calling function already knows where to find the result. IMO the function's type would just be
void
in this case, unless you need to returnint
for a success/error code, but there may be another reason for it.I don't understand why there's a field for initials in the parameters of the function, in C, when those are what you're trying to get. Could someone explain?