C string memcpy() function
Example
Copy the values of an array into another array:
int myNumbers[5] = {10, 20, 30, 40, 50};
int myCopy[5];
memcpy(myCopy, myNumbers, sizeof(myNumbers));
for (int i = 0; i < 5; i++) {
printf("%d %d\n", myNumbers[i], myCopy[i]);
}
Try it Yourself »
Definition and Usage
The memcpy() function copies data from one block of memory to another.
The memcpy() function is defined in the <string.h> header file.
Syntax
memcpy(void * destination, void * source, size_t size);
The size_t data type is a positive integer.
Parameter Values
| Parameter | Description |
|---|---|
| destination | Required. A pointer to the block of memory to be copied to. |
| source | Required. A pointer to the block of memory being copied. |
| size | Required. The amount of data to copy measured in bytes. |
Technical Details
| Returns: | A void type pointer to the destination. |
|---|