English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C / C ++memcpy() function in

This functionmemcpy()Used to copy a storage block from one position to another. One is the source, and the other is a pointer to the destination. This is declared in the 'string.h' header file using C language. It does not check for overflow.

This ismemcpy()C language syntax,

void *memcpy(void *dest_str, const void *src_str, size_t number)

Here,

dest_str-Pointer to the destination array.

src_str-Pointer to the source array.

Number-bytes, copied from source to destination.

This ismemcpy()C language example,

Example

#include <stdio.h>
#include <string.h>
int main () {
   char a[] = "Firststring";
   const char b[] = "Secondstring";
   memcpy(a, b, 5);
   printf("New arrays: %s	%s", a, b);
   return 0;
}

Output result

New arrays: SeconstringSecondstring

In the above program, two char type arrays are initialized,memcpy()The function copies the source string 'b' to the destination string 'a'.

char a[] = "Firststring";
const char b[] = "Secondstring";
memcpy(a, b, 5);