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

前端 未结 12 2187
灰色年华
灰色年华 2020-12-09 09:36

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 followi

12条回答
  •  半阙折子戏
    2020-12-09 10:10

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

    The 2nd option works only if you added back the missing ) and dst is a static array (i.e. of type int[123]).

    If dst has unknown size (i.e. int[]), then sizeof dst only returns the pointer size, since dst has been decayed to a pointer. In this case, you need to use sizeof(*dst)*ARRAY_LENGTH.

提交回复
热议问题