memcpy()
This method as the name suggest memcpy() i.e memory copy is used to copy a number of bytes i.e a block of memory from one location to another location.
Syntax of memcpy():
void * memcpy(void *to, const void *from, size_t numBytes);
Program to demonstrate memcpy() method in C:
/* A C program to demonstrate working of memcpy */
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[] = "Demo";
char str2[] = "First";
puts("str1 before memcpy ");
puts(str1);
/* Copies contents of str2 to sr1 */
memcpy (str1, str2, sizeof(str2));
puts("\nstr1 after memcpy ");
puts(str1);
return 0;
}
Output:
str1 before memcpy
Demo
str1 after memcpy
First
0 Comment(s)