C memcpy()

The memcpy() function copies count characters from the array pointed to by from into the array pointed to by to. If arrays overlap, the behaviour of memcpy() is undefined.

The memcpy() function returns a pointer to to.

memcpy() Syntax

Following is the syntax of the memcpy() function :

void *memcpy(void *to, const void *from, size_t count);

memcpy() Example

Following program copies the contents of buf1 into buf2 and displays the result :


#define SIZE 80

void main()
	char buf1[SIZE], buf2[SIZE];
	strcpy(buf1, "When, in the course of...");
	memcpy(buf2, buf1, SIZE);

C Online Test

« Previous Chapter Next Function »

Like/Share Us on Facebook 😋