memcpy vs for loop - What's the proper way to copy an array from a pointer?

前端 未结 6 1435
误落风尘
误落风尘 2020-12-13 00:33

I have a function foo(int[] nums) which I understand is essentially equivalent to foo(int* nums). Inside foo I need to copy the conte

6条回答
  •  时光说笑
    2020-12-13 00:56

    Essentially, as long as you are dealing with POD types (Plain Ol' Data), such as int, unsigned int, pointers, data-only structs, etc... you are safe to use mem*.

    If your array contains objects, use the for loop, as the = operator may be required to ensure proper assignment.

提交回复
热议问题