memcpy(), what should the value of the size parameter be?

Posted by Tomas on Stack Overflow See other posts from Stack Overflow or by Tomas
Published on 2010-04-21T07:34:21Z Indexed on 2010/04/21 7:43 UTC
Read the original article Hit count: 354

Filed under:
|
|
|
|

Hi,

I want to copy an int array to another int array. They use the same define for length so they'll always be of the same length.

What are the pros/cons of the following two alternatives of the size parameter to memcpy()?

memcpy(dst, src, ARRAY_LENGTH*sizeof(int));

or

memcpy(dst, src, sizeof(dst);

Will the second option always work? Regardless of the content?

One thing that favors the last one is that if the array were to change, it'll be some house-keeping to update the memcpy()'s.

Thanks

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++