CodeCogs
HomeForumsCart
Login



Forgotten Password?

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
ComputingCString.h

memcpy

Copy memory area

Interface

#include <string.h> void memcpy ( void *dst, const void *src, size_t len )

Description

The memcpy function copies len bytes from memory area src to memory area dst. If src and dst overlap, behavior is undefined. Applications in which src and dst might overlap should use reference:memmove instead.

Example 1

#include <stdio.h>
#include <string.h>
 
int main()
{
  // define two arrays u, v and initialize u
  int u[5] = {1, 2, 3, 4, 5}, v[5];
 
  // copy u to v
  memcpy(v, u, 5*sizeof(int));
 
  // display v
  for (int i = 0; i < 5; ++i)
    printf("v[%d] = %d\n", i, v[i]);
 
  return 0;
}

Output:
v[0] = 1
v[1] = 2
v[2] = 3
v[3] = 4
v[4] = 5

Return Values

The memcpy function returns the original value of dst.

Last Modified: 1 Nov 09 @ 11:07     Page Rendered: 2022-03-14 15:50:19