In c language, we generally prefer memcpy to copy the n bytes from one memory location to another memory location.In memcpy we pass the starting address of source and destination buffer to copy n bytes. memcpy perform the forward operation to copy n bytes from source to destination buffer (character array).

Syntax of memcpy in c

Parameters

pvDestination — This is the pointer to the destination buffer,where data is to be copied.
pvSource — This is the pointer to the source buffer,from where data is to be copied.
n — Number of bytes to copy.

Return value

This function returns the pointer to the destination buffer.

Remember the following points before using the memcpy in c

  • size of the destination buffer should be greater then the number of byte you want to copy because memcpy does not check for null character.
  • Memory of source and destination buffer should not be overlap.

Simple program to describe how to use memcpy in c

OutPut:

Message = How Are you ?

Implement own memcpy in c

Driver program to test the implemented memcpy in c

OutPut:

Message = How Are you ?