for (i = 0; i < n1; i++)
L[i] = arr[l + i];
Because I want to copy a large array,I heard that need to use memcpy.
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
Because I want to copy a large array,I heard that need to use memcpy.
memcpy as the name says, copy memory area. is a C
standard function under string.h
.
void *memcpy(void *dest, const void *src, size_t n);
The memcpy()
function copies n
bytes from memory area src
to memory
area dest
. The memory areas must not overlap
. Use memmove(3) if the
memory areas do overlap. The memcpy()
function returns a pointer to
dest.
for more details goto man7: memcpy
so in your case the call would be:
memcpy(L, &arr[l], n1*sizeof(arr[l]));
sizeof one array elementis:
sizeof(arr[l])
make sure that (l+n1)
doesnot exceeds the array boundaries! its you responsibility.
memcopy(destination, source, length)
That would be in your case:
int len = sizeof(int) * n1;
memcopy(L, arr+l, len);
Note: You may have to fix the length calculation according to the type you are using. Moreover, you should also remember to add 1 to include the \0 character that terminates char arrays if you are dealing with strings.