Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of memcpy function in C language

Shulou Source: shulou.com Published: 2022-06-01 02:59:12 09月22日 Update

This article mainly shows you "what is the use of memcpy function in C language", the content is easy to understand, clear, hope to help you solve doubts, the following let Xiaobian lead you to study and learn "what is the use of memcpy function in C language" this article.

Memcpy

Function: memory copy

Function prototype:

Void * memcpy (void * dest, const void * src, size_t count)

Use:

Format: memcpy (destination, original, memory size you want to manipulate (in bytes))

Copy the "Parameter 3" byte content starting from "Parameter 2" to "Parameter 1"

The memecpy function is similar to strncpy.

Example:

# include # include # include int main () {int aa [] = {1pr 2pc 3P 4}; int bb [10] = {0}; memcpy (bb, aa, 4 * sizeof (int)); / / copy the contents of 4 bytes (each int type is 4 bytes) in the aa array to the bb array for (int I = 0; I)

< 10; i++) //打印bb数组全部数据 { printf("%d ", bb[i]); } } 最后bb字符串中前4*4个字节的内容被改为aa的内容

Note: memcpy cannot copy overlapping memory.

# include # include # include int main () {int aa [] = {1, 2, 7, 8, 9, 10}; my_memcpy (aa + 2, aa, 24); for (int I = 0; I < 10; iBex +) {printf ("% d", aa [I]);}}

Output:

This problem occurs when copying overlapping memory.

These are all the contents of the article "what is the use of memcpy functions in C language". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Content function copy memory byte language parameter array article learning help function unit prototype size character string data easy to understand more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Huawei Docker Apple Shulou Information