Using memcpy in C++
问题 I am little confused on the parameters for the memcpy function. If I have int* arr = new int[5]; int* newarr = new int[6]; and I want to copy the elements in arr into newarr using memcopy , memcpy(parameter, parameter, parameter) How do I do this? 回答1: So the order is memcpy(destination, source, number_of_bytes) . Therefore, you can place the old data at the beginning of newarr with memcpy(newarr, arr, 5 * sizeof *arr); /* sizeof *arr == sizeof arr[0] == sizeof (int) */ or at the end with