Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

What is purpose of void return and arguments in memcpy() ?

From 'C' book, here is memcpy() function:

void *memcpy(s, ct, n)

s is type     * void
ct is type    const void *

copy n characters from ct to s, return s

What is purpose of void arguments and void return type in this function?  Does memcpy() typecast   s   and   ct   to  * char ?  
How is  s   defined in calling code?  It's pointer to what?   What will calling code typecast memcpy() return value to ?
Avatar of Zoppo
Flag of Germany image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of naseeam


It helps but return type is not void.  It's  * void.
what does i.o.w. stand for ?
Ah, sorry, I didn't really think about this or checked it. Of course it's a void* too.

The returned pointer is just the same as passed as first argument. I don't think the returned value is often used in a senseful way, at least I never saw code which really used it since it's well known anyway. The only useful situation I can think of is when someone wants to 'chain' multiple function calls - i.e. if someone wants to copy a memory block and search for a character with memchr within the copied memory you could write it somehow like this:
void* p = memchr( memcpy( pDest, pSrc, nLen ), 'A', nLen );

Open in new window

I for myself won't write code this way since IMO it's better readable to put it in separate lines.